Why Ruby?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Dec 16 11:52:16 PST 2010
On 12/16/10 1:30 PM, 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.
I understand. Using strings is witnessing the fact that we couldn't find
a shorter syntax that didn't have problems. That being said, it's very
possible there are some great ones, we just couldn't find them.
Andrei
More information about the Digitalmars-d
mailing list