[Rd] callCC in 2.7.0

Luke Tierney luke at stat.uiowa.edu
Wed Apr 2 18:58:34 CEST 2008


On Tue, 1 Apr 2008, Dr. Ferdinand Jamitzky wrote:

> Anyway something like "yield" would be very nice to have.
> Would it be hard to implement?

Short answer: yes, it would be hard.

Longer answer: R's interpreter is based on lots of recursive C calls.
There are standard ways of implementing continuations in that sort of
context, but they are not entirely portable (involves C stack
copying), require assembly language programming on some platforms
(register window flushing on sparc for example) and can be fairly
inefficient.  It might be possible to implement something more
restricive that is sufficient for implementing generators, but I don't
think it would be much easier given the current architecture.  It is
worth keeping this in mind if we make changes to the evaluator, but
that is not likely to happen real soon.  Some of us worked on
something along these lines a while back in a branch called R-uthreads,
but the cost of converting to that approach and the overhead of
maintaining it seemed too high for the benefit, at least at the time.

Best,

luke

> It could be in a similar way to scala where you can define for-comprehensions.
> I really miss them in R.
> best wishes
> ferdinand
>
> On Tue, Apr 1, 2008 at 12:32 PM, Luke Tierney <luke at stat.uiowa.edu> wrote:
>> No.  First class continuations of the kind provided in scheme can be
>>  used as a means to implement generators, but downward-only
>>  continuations as currently provided in R are not sufficient for that.
>>  This version is intended only as a non-local exit mechanism.
>>
>>  Best,
>>
>>  luke
>>
>>  On Mon, 31 Mar 2008, f.jamitzky wrote:
>>
>> >
>> > callcc is similar to the "yield" keyword in python and c#
>> > it lets you define e.g. a generator of lists of numbers.
>> >
>> >
>> >
>> >
>> > Gabor Grothendieck wrote:
>> >>
>> >> Would anyone like to explain if callCC in R 2.7.0 gives
>> >> anything that on.exit does not already provide?
>> >>
>> >> It seems that the exit condition once defined cannot
>> >> be added to overridden whereas with on.exit multiple
>> >> on.exit's add additional on.exits rather than being ignored.
>> >>
>> >> Is this important?
>> >>
>> >> ______________________________________________
>> >> R-devel at r-project.org mailing list
>> >> https://stat.ethz.ch/mailman/listinfo/r-devel
>> >>
>> >>
>> >
>> >
>>
>>  --
>>  Luke Tierney
>>  Chair, Statistics and Actuarial Science
>>  Ralph E. Wareham Professor of Mathematical Sciences
>>  University of Iowa                  Phone:             319-335-3386
>>  Department of Statistics and        Fax:               319-335-3017
>>     Actuarial Science
>>  241 Schaeffer Hall                  email:      luke at stat.uiowa.edu
>>  Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu
>>
>
>
>
>

-- 
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:      luke at stat.uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



More information about the R-devel mailing list