Re: [R] functional (?) programming in r

From: Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk_at_idi.ntnu.no>
Date: Mon, 17 Nov 2008 22:47:48 +0100

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@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.
>>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 17 Nov 2008 - 21:49:41 GMT

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 Mon 17 Nov 2008 - 22:30:26 GMT.

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

list of date sections of archive