Skip to content
Prev 40095 / 63421 Next

Curry: proposed new functional programming, er, function.

I too would like this (being an Indian!).

Here is an example that came up just yesterday with regards to solving a quadrature problem using the "cubature" package.  The adaptIntegrate function does not allow additional arguments via ...

Uwe suggested a work around, but `Curry' would solve it nicely (and it also tastes better!):

Curry = function(FUN,...) { 
.orig = list(...)
function(...) do.call(FUN,c(.orig, list(...))) 
}

require(cubature)

f <- function(x, a) cos(2*pi*x*a)  # a simple test function

# this works
a <- 0.2
adaptIntegrate(function(x, argA=a) f(x, a=argA), lower=0, upper=2)

# but this doesn't work
rm(a)
adaptIntegrate(function(x, argA=a) f(x, a=argA), lower=0, upper=2, a=0.2)


# Use of Curry
adaptIntegrate(Curry(f, a=0.2), lower=0, upper=2)

Best,
Ravi.

-------------------------------------------------------
Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu


-----Original Message-----
From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-project.org] On Behalf Of Hadley Wickham
Sent: Wednesday, May 04, 2011 10:29 AM
To: Byron Ellis
Cc: R Development Mailing List
Subject: Re: [Rd] Curry: proposed new functional programming, er, function.

I thought I might bring this up again - it now seems like Curry would
be a natural fit with Reduce, Filter, Find, Map, Negate and Position.
Any chance we might see this in a future version of R?

Hadley
On Thu, Nov 1, 2007 at 2:00 PM, Byron Ellis <byron.ellis at gmail.com> wrote: