double-tilde: syntax sugar of making an anonymous function

Description Usage Arguments Details Examples

Description

Tilde is a R's "Primitive Function" that does not evaluate its argument, and it is normally used to create a formula object as an inner-DSL role. I hijack this functionality to make an anounymous function. Double-tilde with a two-dots symbol, .., makes an anonymous function in which two-dots plays a placeholder. If you need two or more arguments, the placeholde should be ..1, ..2, and so on. See examples. Single tilde works as if it is normaly used but it takes a bit calulation process, and not fully tested.

Usage

1
2
3
"~~"(...)

"~"(e1, e2)

Arguments

...

any valid expression

e1, e2

The original-tilde is both unary and binary function. if e2 is missing and the first call object of e1 is ~ symbol itself, then an anonymous function is made.

Details

Unsupported nested lambda. function(x) function(y) x + y cannot define by double-tilde. Use f. and type this; f.(x, f.(y, x + y))

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
~~ .. + 1 # => function(..) .. + 1
~~ ..1 + ..2 # => function(._1, ._2) ._1 + ._2

Reduce(~~ ..1 + ..2, 1:10)
Filter(~~ .. %% 3 == 0, 1:10)

# The tilde's role remains.
~ speed + dist
lm(speed ~ dist, data = cars)
lm(mpg ~ ., data = mtcars)

TobCap/lambdass documentation built on May 9, 2019, 4:50 p.m.