From hadley at rice.edu  Wed May  4 17:53:33 2011
From: hadley at rice.edu (Hadley Wickham)
Date: Wed, 4 May 2011 10:53:33 -0500
Subject: [Rd] Curry: proposed new functional programming, er, function.
In-Reply-To: <alpine.DEB.2.00.1105041012020.4973@luke-inspiron>
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>
Message-ID: <BANLkTinSwtgGKDPLxc6o6RmKOpP1zEv2VA@mail.gmail.com>

>> # Use of Curry
>> adaptIntegrate(Curry(f, a=0.2), lower=0, upper=2)
>
> The _concept_ of currying is useful, and maybe more can be done to
> provide guidance and education on how to do it, but adding a function
> that sometimes works and somesimes does surprising things is not the
> way to go.

What about an alternative approach?

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

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

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)))
    }


I think this is pretty close to what you'd get if you made an
anonymous function (but I'm probably missing something)

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