[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Continuations in Ruby v. Scheme

On Wed, 3 Apr 2002, Peter J. Wasilko, Esq. wrote:

>     I just picked up a copy of 'Ruby in a Nutshell' and noticed that the
> language supports 'callcc' and has a 'continuation' class as well as a 'binding'
> class.
>     Can anyone comment on how these facilities stack up against Scheme
> continuations and closures?

Continuations in Ruby are the same, in the abstract, as in Scheme.  The
main ways in which closures and continuations differ in Ruby and Scheme are:

- Ruby does not have the dynamic-wind construct
- Blocks (closures) in Ruby do not introduce a new scope, only methods do.
This is generally acknowledged as a flaw by the Ruby community but is left
in for backwards compatibility.  For example:

x = 0
[1,2,3].each{|x| print x}
#x now equals 3

Except for when shadowing variable names, however, Ruby's closures
are semantically the same as Scheme's (and yes, that's a big "except").

>     Would it be feasible to write a Scheme to Ruby translator?

Not easily, because of the scope issue above.