Prepare expression for evaluation in context
prepare_expression(expr, envir, db, function_value = NULL)
A quoted expression consisting of a single function call.
An environment to find variables local to the expression
A database to store locals
Optionally, the value of a function
where the expression should involve an anonymous function. In
this case the function in expr
will be replaced.
The function_value
argument here is used where expr
is
going to take a function that is not addressable by name; in
that case we take a function itself (as "function_value"),
serialise it and replace the function call with the hash. The
function will be serialised into the calling environment on
deserialisation.
This includes the remote possibility of a collision, but with the size of the keyspace used for hashes hopefully it's negligible.
Because of the approach used here, expr
can contain
anything; I'd suggest not saving the contents of the function
itself, but something like NULL
will work just fine: