vadr (version 0.01)

macro: Turn an expression-substituting function into a nonstandard-evaluating function.

Description

This just places a wrapper around the function that un-quotes all arguments and evaluates the result.

Usage

macro(fn, cache = TRUE, JIT = cache)

Arguments

fn
A function which takes some arguments and returns a trane
cache
Whether to store already-compiled macros for faster evaluation. Defaults to TRUE. This requires that the macro function be a pure function not referring to any outside state.
JIT
Whether to compile expressions (using the "compiler" package) before executing. Defaults to TRUE if "cache" is true.

Value

the wrapper function. It will have an identical argument list to the wrapped function. It will transform all arguments into expressions, pass the expressions to the wrapped function, then evaluate the result it gets back.The advantage of macros versus usual nonstandard evaluation using substitute, link{eval} and friends is that it encourages separating "computing on the language" from "computing on the data." Because code is usually static while data is variable, the language transformations only need to happen once per each call site. Thus the expansions of macros can be cached, enabling complicated code transformations with smaller performance penalties.

See Also

qq