[R] functional (?) programming in r

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Mon Nov 17 22:47:48 CET 2008


so just to show how scheme would do that:

(map
   (lambda (function) (function))
   (map
      (lambda (index) (lambda () index))
      '(1 2 3 4 5)))
;; *this* is the scheme semantics

vQ

xxx wrote:
> I agree, something is wrong here, especially since the R community
> likes to say that R semantics are based on Scheme....
>
> On Mon, Nov 17, 2008 at 4:28 PM, Wacek Kusnierczyk
> <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:
>   
>> the following is a trivialized version of some functional code i tried
>> to use in r:
>>
>> (funcs = lapply(1:5, function(i) function() i))
>> # a list of no-parameter functions, each with its own closure environment,
>> # each supposed to return the corresponding index when applied to no
>> arguments
>>
>> sapply(funcs, function(func) func())
>> # supposed to return c(1,2,3,4,5)
>>
>> there is absolutely nothing unusual in this code, in the context of
>> functional programming.
>>



More information about the R-help mailing list