[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: yield does not take a block

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...





1 Answer

November 5

8/12/2009 7:30:00 PM

0



Steve Walker wrote:

> Public shoot-outs between rival for-profit police gangs. That'll make the
> community feel safer, yeah....

It could be that they are just having some business competition for
you. Surely you would only want to hire a police company that can
handle itself in a firefight?

As it stands the police (monopoly) we have are useless when it comes
to anything resembling a mortal threat to their lives. They have been
known to panic and shoot brown-skinned men in Tube stations, Irishmen
carrying table legs and angry lawyers in their own home.

Or it could be that one private police force discovered corruption in
another, and is fixing the problem. Surely you would expect police
forces to uphold a high moral standard and clean out any dross who
make it into their ranks?

N5