William James
12/12/2004 9:42:00 PM
In the Icon example, find() is a generator. You can write your
own generators:
procedure main()
write( fibo() )
write( fibo() )
write( fibo() )
every f := fibo() do
{ writes( f, " " )
writes( "(", fibo(), ") " )
if f > 80 then
break
}
end
procedure fibo()
local old,new,temp
old := 0
new := 1
while 0 do
{ ## Return 'new' and suspend.
suspend new
temp := new
new +:= old
old := temp
}
end
1
1
1
1 (1) 1 (1) 2 (1) 3 (1) 5 (1) 8 (1) 13 (1) 21 (1) 34 (1) 55 (1) 89 (1)
Does Ruby have generators?