Oh, crap. I already wrote a reply but it didn't end up here for some
reason.

Anyway, the point was not to prove which is better or worse, but it
just got me thinking why is Ruby-s syntax more verbose and how would
it be possible to be improved. If at all. That's all.

When analyzing the differences between Scala and Ruby in that concrete
example then i can see that Scala "wins" by automatically initializing
local variable "_" in the context of "block". In Ruby we have to
specify "&:". It would be already even better if we could drop the "&"
for invoking #to_proc. And the next step would be to drop ":" too.
Technically it should be possible if #select, #map and #sort_by
allowed to instance-eval. Of course it wouldn't look good from the
inside, but it would definitely rock even more from the outside :)

And when in a need to specify full block syntax in Ruby with pipes and
such then there is even more verbosity.

By the way, the example you wrote:
array.select { &:value > 5 }

Is not working unfortunately. I tried it also before. I tried it also
with parentheses instead of curly-braces. It would be awesome if it
worked though:
array.select(&:value > 5)

But why it doesn't work though? Does ".>" have higher precedence over
"&"? How to force "&" have higher precedence so it could work?

Again, i was not trying to create any competition in here, just having
some random thoughts.

Jarmo

On Feb 25, 11:43=A0pm, Adam Prescott <mention... / gmail.com> wrote:
> [Note: =A0parts of this message were removed to make it a legal post.]
>
> On Fri, Feb 25, 2011 at 9:15 PM, Jarmo Pertman <jarm... / gmail.com> wrote:
> > It's still whopping 12 characters longer. So i decided to use
> > different block variable - more Scala-like underscore:
> > sales.select{|_| _.value > 50000}.map(&:buyer).sort_by(&:age)
>
> > Still 6 characters longer. Even if i'd be able to use syntax like
> > this, i'd win only 2 characters:
>
> What's the point of this exercise? Why is "beating" Scala's solution the
> same as getting it shorter?
>
> The original Ruby code and Scala's are equally readable. Contrast their
> readability to the lambdaj code you gave, and there's no more to do. Both
> beat lambdaj without any greater expenditure of effort required. Hacking
> things apart and introducing instance_eval selects is worse than using
> character length!
>
> That said, this does appeal to me:
>
> array.select { &:value > 5 }
>
> Perhaps something could be done with the singleton of the proc resulting
> from Symbol#to_proc, to pass method calls to the block parameter. But the=
n
> perhaps that's just ugly.