Devin Mullins
6/29/2005 7:58:00 PM
> The languages you mentioned above all have this ``arbitrary limit.''
> Consider O'Caml. You can only give one block to the `fun' keyword.
> Or JavaScript. Certainly, the `function' keyword only takes one
> argument list and one code block.
>
> In fact, these languages have the additional ``arbitrary limit'' that
> code blocks cannot be passed to user-defined methods.
Your example is deceptive. In Ruby, def, if, begin, and while all have the same sort of syntax - but do not take a block. They take some lines of code which then have their own independent lexical scope. Just like in those other language, 'fun' is different from everything else.
Ruby, like those other languages, supports the passing of lambda functions, though with not nearly the flexibility that, say, OCaml allows. Ruby also supports blocks, whose syntax is nice, but whose semantic distinction from lambdas is unclear to me.
> a Ruby programmer could go like this ---
>
> array.sort &lambda { |a, b| ... }
>
> that would be the literal translation. But Ruby takes another step;
> it lets you give code blocks directly to _any_ method,
>
> array.sort { |a, b| ... }
>
> not just `lambda'.
Granted.
> This is _better_ than most languages can do.
Why? (And don't say 'syntax', because that can be sweetened -- as you say, 1.9 does just that.)
Devin
Inquisitive, not argumentative...