Skip to content
Prev 53139 / 63421 Next

Support for user defined unary functions

Your example
   x = 5
   exp = parse(text="f(uq(x)) + y +z") # expression: f(uq(x)) +y + z
   do_unquote(expr)
    # -> the language object f(5) + y + z
could be done with the following wrapper for bquote
   my_do_unquote <- function(language, envir = parent.frame()) {
      if (is.expression(language)) {
         # bquote does not go into expressions, only calls
         as.expression(lapply(language, my_do_unquote))
      } else {
         do.call(bquote, list(language, where=envir))
      }
   }
as in
   > x <- 5
   > exp <- parse(text="f(.(x)) + y +z") # dot is uq for bquote
   > exp
   expression(f(.(x)) + y +z)
   > my_do_unquote(exp)
   expression(f(5) + y + z)
Or do uq() and do_unquote() do more than that?  E.g., would
uq() carry information about environments?

[I think expressions should map to expressions and calls to calls.
Otherwise what would we do with multicall expressions?]

We probably need to come up with a better name than 'non-standard
evaluation' since there are lots of non-standard ways of doing things.
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Fri, Mar 17, 2017 at 12:14 PM, Gabriel Becker <gmbecker at ucdavis.edu> wrote: