> From: jweirich / one.net [mailto:jweirich / one.net]
> Sent: Friday, February 16, 2001 08:00 PM
> To: ruby-talk ML
> Subject: [ruby-talk:11007] Generators (was: RCR Summary 02/16/01
> -suspend)
> 
> 
> 
>     Hugh> Icon has the suspend command which allows a function to
>     Hugh> produce a result in the way that return does, but it
>     Hugh> suspends execution so that if the function is called again
>     Hugh> in the same context execution can continue from where the
>     Hugh> suspend left off. It could be considered to be an inside-out
>     Hugh> yield. This is used to create generators rather than
>     Hugh> iterators. It is achieved by leaving the state of the
>     Hugh> function on the stack.
> 
> How about this ...
[really neat example]

I just wanted to point out that besides its beauty this implementation
is unfortunately much slower (maybe fifty times - fib is not a good 
example since it has exponential behavior, so the arithmetic becomes 
the dominating factor for ``moderately large n'') then a more down 
to earth implementation like

class Fib
def initialize
    @a,@b = 1,1
end
def re_initialize
    @a,@b = 1,1
end
def next
@a,@b = @b, @a+@b # this is inefficient since 
@a                # it internally generates an array
end
end

To be competitive  ``suspend'' would have to be natively 
supported.

Christoph