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

Re: rough first impressions



> I haven't programmed very much Ruby, but looking at the Ruby book it
> seems like its iterators are mostly just sugar for higher-order
> functions -- the "yield" keyword lets you pass a function as an
> implicit argument to a method -- ie, you just write
>
>   foo(x) {|n| n + n}
>
> rather than
>
>   foo(x, {|n| n + n })

That's exactly right. Python's yield statement is more powerful and must be
encoded as a coroutinue in the the most general case. However, Ruby does
have full continuations so something resembling Python iterators could be
put together as a library. I'm not sure whether that's a common idiom in
Ruby, though.