[Rd] Curry: proposed new functional programming, er, function.

Hadley Wickham hadley at rice.edu
Wed May 4 18:19:15 CEST 2011


> Or maybe
>
>    Curry <- function(FUN, ...) {
>      args <- match.call(expand.dots = FALSE)$...
>      args$... <- as.name("...")
>
>      curry_call <- as.call(c(list(as.name("FUN")), args))
>      eval(bquote(function(...) .(curry_call)))
>    }

Or one more approach:

    Curry <- function(FUN, ...) {
      args <- match.call(expand.dots = FALSE)$...
      args$... <- as.name("...")

      curry_call <- as.call(c(list(as.name("FUN")), args))
      eval(call("function", as.pairlist(alist(... = )), curry_call))
    }

I'm not sure if there's a canonical way of programmatically creating functions.

Hadley


-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-devel mailing list