Kaz Kylheku
11/9/2015 8:29:00 PM
On 2015-11-09, WJ <w_a_x_man@yahoo.com> wrote:
> MatzLisp (Ruby):
>
> def find_fib
> a = b = 1 ; i = 0
> until yield(a)
> a,b = b,a+b
> i += 1
> end
> [a,i]
> end
>
> find_fib &:even?
> ==>[2, 2]
A complete cluster fuck, demonstrating perfectly how Ruby is a worse-is-better
computer science flunk job.
When a coroutine or continuation yields, it means that its execution is
suspended, producing a value. Another context elsewhere can somehow resume it
(perhaps by calling a resume function) passing it a value which emerges
out of the yield.
What we have here is simply that a hidden argument is added to find_fib,
expected to be a function. yield just invokes that callback.
Some Ruby-pushing imbecile saw a generator or continuation example on someone's
programming blog and decided, "Bah, I can do that; it's just some kind of
implicit callback thingy". When he was later told, "No you aren't actually
doing that", he replied that the callback thingy satisfies 87% of all the use
cases, and it looks all generator-like with the yield word and hidden argument,
and so is good enough.