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

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat, 26 May 2012 13:07:41 -0400

On Sat, May 26, 2012 at 12:30 PM, Yike Lu <yikelu.home_at_gmail.com> wrote:
> On 5/25/12 5:23 PM, Hadley Wickham wrote:
>>
>> On Fri, May 25, 2012 at 3:14 PM, Yike Lu<yikelu.home_at_gmail.com>  wrote:
>>>
>>> So here's the way I'm reading this:
>>>
>>> Original:
>>> curry_call is the function body you're constructing, which is itself just
>>> a
>>> one liner which calls the symbol FUN with the appropriate substitutions.
>>
>>
>> Yup.  With a bit more infrastructure you could probably modify it so
>> that multiple curries collapsed into the equivalent single curry.
>>
> Yes I could see how one would do that - if the match.call detects a Curry as
> the first function being called, we would short circuit the usual evaluation
> into a different path which properly collapses all the nesting.
>
> It's interesting how R offers these facilities to override the usual
> evaluation order, but if one does that too much it could easily become
> confusing. I was looking at Rpipe the other day
> (https://github.com/slycoder/Rpipe) and the way he implements it is by
> defining his own Eval.
>

The proto package does currying on proto methods by defining $.proto appropriately:

library(proto)
p <- proto(a = 1, b = 2)

# same as ls(p) - output is c("a", "b")
p$ls()

Here ls() is _not_ a special proto method but is just the ordinary ls() provided by R. $.proto calls ls() sticking in p as the first argument. A proto object is an environment and ls with a first argument that is an environment lists the names of the objects in that environment. Similarly:

p$as.list()
p$str()
p$parent.env()
p$print()
p$eapply(length)

are the same as as.list(p), str(p), parent.env(p), print(p) and eapply(p, length).

Although this might seem like its just syntax in proto it does allow one to override the method. For example,

p2 <- proto(a = 1, b = 2, print = function(.) with(., cat("a:", a, "b:", b, "\n")) )

p2$print() # uses p2's print

print(p2) # uses R's print

etc.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sat 26 May 2012 - 17:12:40 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 26 May 2012 - 19:22:02 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive