lambda: Construct an anonymous function in infix code

Description Usage Arguments Details Value Examples

View source: R/functional.R

Description

This function provides the Lisp/Scheme lambda form for defining anonymous functions. Its behavior is very similar to R's "function" keyword, but it interprets its arguments in a way that allows it to be used naturally in prefix code. It is not intended to be called the usual way from infix R code.

Usage

1
lambda(params, ...)

Arguments

params

A parameter list, which when coerced to pairlist is acceptable to the "function" constructor function.

...

Body statements.

Details

Because R is a Scheme dialect, this lambda is directly evaluable and evaluates to a function object. Common Lisp's sharp-quote operator is not necessary and not provided.

Value

The constructed function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
schemeR::schemeR({
.(map, .(lambda, .(n), .(paste0, n, "\n")),
       .(list, "a", "b"))
}, pkg=TRUE)

schemeR::schemeR({
.(letrec, .(.(i, 3),
            .(foo, .(lambda, .(n), .(`+`, n, 1)))),
     .(`==`, i, .(foo, 2)))
}, pkg=TRUE)

wwbrannon/schemeR documentation built on May 4, 2019, 12:03 p.m.