[med-svn] [r-cran-lambda.r] 01/05: New upstream version 1.2
Andreas Tille
tille at debian.org
Thu Sep 28 21:21:05 UTC 2017
This is an automated email from the git hooks/post-receive script.
tille pushed a commit to branch master
in repository r-cran-lambda.r.
commit 5df27d375e853efe290e94ca6527521b29d9e3ad
Author: Andreas Tille <tille at debian.org>
Date: Thu Sep 28 23:15:46 2017 +0200
New upstream version 1.2
---
DESCRIPTION | 8 ++---
MD5 | 13 ++++----
NAMESPACE | 1 +
R/framework.R | 61 ++++++++++++++++++++++++++--------
inst/unitTests/runit.function_args.1.R | 14 ++++++++
inst/unitTests/runit.infix.1.R | 18 ++++++++++
man/framework.Rd | 1 +
man/lambda.r-package.Rd | 22 +++++++++---
8 files changed, 109 insertions(+), 29 deletions(-)
diff --git a/DESCRIPTION b/DESCRIPTION
index ebbfeaf..55d3b95 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,8 +1,8 @@
Package: lambda.r
Type: Package
Title: Modeling Data with Functional Programming
-Version: 1.1.9
-Date: 2016-07-10
+Version: 1.2
+Date: 2017-09-12
Depends: R (>= 3.0.0)
Suggests: RUnit
Author: Brian Lee Yung Rowe
@@ -11,6 +11,6 @@ Description: A language extension to efficiently write functional programs in R.
License: LGPL-3
LazyLoad: yes
NeedsCompilation: no
-Packaged: 2016-07-10 13:33:55 UTC; brian
+Packaged: 2017-09-16 17:33:39 UTC; brian
Repository: CRAN
-Date/Publication: 2016-07-10 16:30:57
+Date/Publication: 2017-09-16 18:51:43 UTC
diff --git a/MD5 b/MD5
index 8204aba..54749fa 100644
--- a/MD5
+++ b/MD5
@@ -1,7 +1,7 @@
-522b07ad4e394663c2d9c15fd2f40add *DESCRIPTION
-ab82d9729386261d282f5fc0d8b3d5f4 *NAMESPACE
+4e92c39cf64e3824ba4cd11eb898da6e *DESCRIPTION
+ca3a1ecc796004a7df7fff727b9a071a *NAMESPACE
1f1c9a9a097262fe0f7e3517eacefbee *R/duck.R
-7c016c2b35276b2364a9b78613a04ed2 *R/framework.R
+faad7505b495be721120b590f71a2089 *R/framework.R
adac14153bc41e3607ed9dec5da7830a *R/introspection.R
c5d9ed228976ea81509c224506d65f2f *R/objects.R
97ceabf07d26fc1d390ed1bff9cceb55 *inst/unitTests/runit.auto_replace.1.R
@@ -14,10 +14,11 @@ cb96ac32893792bd0fc5522e1d7deff6 *inst/unitTests/runit.examples.R
f51390873d9ace14ff2c3c55a0867d35 *inst/unitTests/runit.factorial.1.R
080c9faea036e772a4bd4dd02dac65fa *inst/unitTests/runit.factorial.2.R
253426aaff845e9ffe8525e9c974f9c9 *inst/unitTests/runit.fill_args.R
-9ee9fe941b00e243dff4d603fde446d7 *inst/unitTests/runit.function_args.1.R
+1e71378d1ff9e32ee99992aa92189603 *inst/unitTests/runit.function_args.1.R
d00182c9d7417129db68fc46d62fe471 *inst/unitTests/runit.function_type.1.R
65d13a07127f9509f88b624c6d16bb46 *inst/unitTests/runit.heaviside_step.1.R
979dce6f4f885fee49c796de79ec1ec8 *inst/unitTests/runit.heaviside_step.2.R
+9dfabd92c09733909552ad26bccd8fc0 *inst/unitTests/runit.infix.1.R
9a61eb814b14d27344b3754263c153a0 *inst/unitTests/runit.optional_arguments.1.R
c72938f7a98c6447fcbd768df14a717e *inst/unitTests/runit.optional_arguments.2.R
cf791378a6213f7e874142eef8740170 *inst/unitTests/runit.parse_transforms.1.R
@@ -34,7 +35,7 @@ ae772e8e2067de9da0b2b65d49d6afe8 *inst/unitTests/runit.type_functions.R
c6c8fe9189580c87fe3e35b0de73365b *inst/unitTests/runit.types.1.R
a2c77e08d37644ae9f2ad53a00a487de *man/UseFunction.Rd
7954e4e489368550f3b029ae69756bc3 *man/duck.Rd
-7ed5820d3134d7d8e93ca02257b8af1b *man/framework.Rd
+c6780ccc995ee695572bc53982194816 *man/framework.Rd
ad73256313b25f4a7ab5079204872ebd *man/introspection.Rd
-852aa917958ed85a17251526222fae9f *man/lambda.r-package.Rd
+9ab04d13bf4d3335d155e358ec28b7f7 *man/lambda.r-package.Rd
8e4fcf20f64e5f762f1e52d089e32ee9 *tests/doRUnit.R
diff --git a/NAMESPACE b/NAMESPACE
index 719e5bb..4b206d9 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,5 +1,6 @@
importFrom("utils", "capture.output", "getParseData", "str", "tail")
export("%as%")
+export("%:=%")
export("%::%")
export("UseFunction")
export("NewObject")
diff --git a/R/framework.R b/R/framework.R
index 88a0810..848bad2 100644
--- a/R/framework.R
+++ b/R/framework.R
@@ -20,7 +20,12 @@ is.bound <- function(name) {
it <- iterator(raw)
tree <- list(args=NULL)
- args_expr <- parse_fun(it)
+ args_expr <- parse_infix(raw)
+ if (is.null(args_expr)) {
+ args_expr <- parse_fun(it)
+ } else {
+ fast_forward(it, '%::%')
+ }
name <- args_expr$token[1]
if (is.bound(name))
stop("Function name is already bound to non lambda.r object")
@@ -47,10 +52,16 @@ is.bound <- function(name) {
raw <- getParseData(parse(text=text))
# SPECIAL tokens now appear with a leading white space
raw$text <- sub("^ ","", raw$text)
+ raw$text <- sub("%:=%","%as%", raw$text, fixed=TRUE)
it <- iterator(raw)
-
tree <- list(args=NULL)
- args_expr <- parse_fun(it)
+
+ args_expr <- parse_infix(raw)
+ if (is.null(args_expr)) {
+ args_expr <- parse_fun(it)
+ } else {
+ fast_forward(it, c('%as%','%when%'))
+ }
name <- args_expr$token[1]
if (is.bound(name))
stop("Function name is already bound to non lambda.r object")
@@ -81,6 +92,8 @@ is.bound <- function(name) {
invisible()
}
+'%:=%' <- `%as%`
+
################################## RUN TIME ###################################
.ERR_NO_MATCH <- "No match for function"
.ERR_USE_FUNCTION <- "No valid function for"
@@ -434,8 +447,9 @@ iterator <- function(tree)
if (!is.null(tree)) tree <- tree[! (tree$token=='expr' & tree$text==''),]
cap <- nrow(tree) + 1
idx <- 0
- function(rewind=FALSE)
+ function(rewind=FALSE, dump=FALSE)
{
+ if (dump) return(tree[idx:nrow(tree),])
if (rewind) idx <<- idx - 1
else idx <<- idx + 1
if (idx < cap) tree[idx,]
@@ -443,18 +457,34 @@ iterator <- function(tree)
}
}
-get_name <- function(it)
-{
+get_name <- function(it) {
line <- it()
if (line$token != 'SYMBOL_FUNCTION_CALL')
stop("Function must start with a symbol (instead of ",line$token,")")
line$text
}
+fast_forward <- function(it, what) {
+ while (!is.na(line <- it()) && ! line$text %in% what) { }
+ it(rewind=TRUE)
+}
+
+parse_infix <- function(raw) {
+ raw <- raw[raw$token != 'expr' & raw$terminal,]
+ raw <- raw[1:nrow(raw) < which(raw$text %in% c('%as%','%::%','%when%'))[1],]
+ if (! identical(raw$token, c('SYMBOL','SPECIAL','SYMBOL'))) return(NULL)
+
+ fn.name <- raw$text[raw$token=='SPECIAL']
+ arg.name <- raw$text[raw$token=='SYMBOL']
+ data.frame(paren.level=c(0,1,1),
+ node=c('function.name','argument','argument'),
+ token=c(fn.name,arg.name),
+ pattern=NA, default=NA, stringsAsFactors=FALSE)
+}
+
# parse_fun(raw=parser(text="fib(0,y=some.fun(1)) %as% 1"))
# parse_fun(raw=parser(text="fib(x,y=some.fun(1), 'bgfs') %as% 1"))
-parse_fun <- function(it, raw=NULL)
-{
+parse_fun <- function(it, raw=NULL) {
if (!is.null(raw)) { it <- iterator(raw) }
name <- get_name(it)
paren.level <- 0
@@ -663,10 +693,9 @@ transform_attrs <- function(tree)
do.call(rbind, lines)
}
-is.type <- function(fn.string)
-{
- length(grep('^[A-Z]', fn.string)) > 0
-}
+is.type <- function(fn.string) { grepl('^[A-Z]', fn.string) }
+
+is.infix <- function(fn.string) { grepl('^%[^%]+%$', fn.string) }
parse_body <- function(it)
@@ -930,10 +959,14 @@ setup_parent <- function(parent, where)
init_function <- function(name, where)
{
- if (is.type(name))
+ if (is.type(name)) {
pattern <- 'function(...) NewObject(%s,"%s",...)'
- else
+ } else if (is.infix(name)) {
+ pattern <- 'function(...) UseFunction(`%s`,"%s",...)'
+ } else {
pattern <- 'function(...) UseFunction(%s,"%s",...)'
+ }
+
fn <- eval(parse(text=sprintf(pattern,name,name)), where)
if (is.type(name))
attr(fn, 'class') <- c('lambdar.type', 'function')
diff --git a/inst/unitTests/runit.function_args.1.R b/inst/unitTests/runit.function_args.1.R
index 2c960a6..b283fd3 100644
--- a/inst/unitTests/runit.function_args.1.R
+++ b/inst/unitTests/runit.function_args.1.R
@@ -25,3 +25,17 @@ test.function_args_3 <- function() {
act <- f(3)
checkEquals(act,3)
}
+
+test.function_args_4 <- function() {
+ f() %::% numeric
+ f() %:=% 1
+ f(a) %::% numeric : numeric
+ f(a) %:=% a
+ seal(f)
+
+ act <- f()
+ checkEquals(act,1)
+ act <- f(3)
+ checkEquals(act,3)
+}
+
diff --git a/inst/unitTests/runit.infix.1.R b/inst/unitTests/runit.infix.1.R
new file mode 100644
index 0000000..203de7d
--- /dev/null
+++ b/inst/unitTests/runit.infix.1.R
@@ -0,0 +1,18 @@
+test.infix.1 <- function() {
+ a %mod% b %:=% { a %/% b }
+ seal(`%mod%`)
+
+ act <- 5 %mod% 2
+ exp <- 5 %/% 2
+ checkEquals(act, exp)
+}
+
+test.infix.2 <- function() {
+ a %mod% b %as% { a %/% b }
+ seal(`%mod%`)
+
+ act <- 5 %mod% 2
+ exp <- 5 %/% 2
+ checkEquals(act, exp)
+}
+
diff --git a/man/framework.Rd b/man/framework.Rd
index 481f5fa..e1653b2 100644
--- a/man/framework.Rd
+++ b/man/framework.Rd
@@ -1,5 +1,6 @@
\name{\%as\%}
\alias{\%as\%}
+\alias{\%:=\%}
\alias{\%::\%}
\alias{EMPTY}
\alias{seal}
diff --git a/man/lambda.r-package.Rd b/man/lambda.r-package.Rd
index fc73ac3..38349e5 100644
--- a/man/lambda.r-package.Rd
+++ b/man/lambda.r-package.Rd
@@ -23,8 +23,8 @@ and convenient syntax that reduces type clutter.
\tabular{ll}{
Package: \tab lambda.r\cr
Type: \tab Package\cr
-Version: \tab 1.1.9\cr
-Date: \tab 2016-07-10\cr
+Version: \tab 1.2\cr
+Date: \tab 2017-09-12\cr
License: \tab LGPL-3\cr
LazyLoad: \tab yes\cr
}
@@ -47,8 +47,9 @@ in addition to making programs modular and easier to maintain.
\subsection{Function Definition}{
-Functions are defined using the \code{\%as\%} symbol in place of \code{<-}.
-Simple functions can be defined as simply as
+Functions are defined using the \code{\%as\%} (or \code{\%:=\%}) symbol
+in place of \code{<-}.
+Simple functions can be defined as simply
\preformatted{f(x) \%as\% x }
and can be called like any other function.
\preformatted{f(1) }
@@ -56,7 +57,18 @@ and can be called like any other function.
Functions that have a more complicated body require braces.
\preformatted{f(x) \%as\% { 2 * x }
-g(x, y) \%as\% {
+g(x, y) \%:=\% {
+ z <- x + y
+ sqrt(z)
+}
+}
+
+\subsection{Infix notation}{
+Functions can be defined using infix notation as well.
+For the function \code{g} above, it can be defined as an infix operator
+using
+
+x \%g\% y \%:=\% {
z <- x + y
sqrt(z)
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/r-cran-lambda.r.git
More information about the debian-med-commit
mailing list