Why Ruby?

Justin Johansson noreply at jj.com
Fri Dec 17 08:02:29 PST 2010


On 17/12/10 06:30, Jacob Carlborg wrote:
> On 2010-12-15 23:33, Andrei Alexandrescu wrote:
>> On 12/15/10 4:18 PM, retard wrote:
>>> Wed, 15 Dec 2010 22:23:35 +0100, Jacob Carlborg wrote:
>>>> Array(1, 2, 3, 4, 5).sortWith(_> _)
>>>
>>> The first instance of _ (from left to right) is replaced with the first
>>> element of the parameter tuple, the second with second element, etc.
>>>
>>> This is actually very useful since many lambdas only use 1-2 parameters.
>>> It has its limitations. For example referring to the same parameter
>>> requires a named parameter or some other hack. Combined with Haskell
>>> style partial application this allows stuff like:
>>>
>>> Array(1, 2, 3, 4, 5).foreach { println }
>>>
>>> Array(1, 2, 3, 4, 5).filter(2<)
>>
>> For short lambdas I prefer Phobos' convention of using "a" and "b", e.g.
>> "2 < a" or "a < b". Since it's a string, "_ < _" would have been usable
>> with Phobos too but I wouldn't like such a change.
>>
>> Andrei
>
> The point here isn't that we want "a" and "b" to be replaced with "_"
> the point is that we want to get rid of the string and have a shorter
> and less verbose syntax for delegate literals.

The point you point out is a good point. :-)  3 points

Using strings for the delegate literals is just so JavaScript-ish and 
less than ideal.  What escape mechanism must one use when strings are 
argued rather than the simple arithmetic/numeric examples usually 
demonstrated for this type of construct?

Cheers
Justin


More information about the Digitalmars-d mailing list