From hadley at rice.edu  Wed May  4 18:19:15 2011
From: hadley at rice.edu (Hadley Wickham)
Date: Wed, 4 May 2011 11:19:15 -0500
Subject: [Rd] Curry: proposed new functional programming, er, function.
In-Reply-To: <BANLkTinSwtgGKDPLxc6o6RmKOpP1zEv2VA@mail.gmail.com>
References: <7098abec0711011200va3851o811f60bb100616ce@mail.gmail.com>
	<BANLkTi=jud5hhis5y-veQKZHzSYYoPqnBw@mail.gmail.com>
	<79F23BA7BB084E4FA01A8B93904CD02CF669FAA4C9@WIGGUMVS.win.ad.jhu.edu>
	<alpine.DEB.2.00.1105041012020.4973@luke-inspiron>
	<BANLkTinSwtgGKDPLxc6o6RmKOpP1zEv2VA@mail.gmail.com>
Message-ID: <BANLkTi=zr-eSQVu2mb2BG1axTBbSS0xx_g@mail.gmail.com>

> 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/



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