Project Elvis

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Oct 30 19:46:54 UTC 2017


On 10/30/17 7:32 AM, Dejan Lekic wrote:
> On Saturday, 28 October 2017 at 11:38:52 UTC, Andrei Alexandrescu wrote:
>> Walter and I decided to kick-off project Elvis for adding the homonym 
>> operator to D.
>>
>> Razvan Nitu has already done a good part of the work:
>>
>> https://github.com/dlang/dmd/pull/7242
>> https://github.com/dlang/dlang.org/pull/1917
>> https://github.com/dlang/dlang.org/pull/1918
> 
> Is it going to be something similar (or the same) as in Kotlin? 
> (Reference: 
> https://kotlinlang.org/docs/reference/null-safety.html#elvis-operator )
> 
> I see from comments that different people think of it in a different 
> way. I suggest them to read this section from Kotlin docs to understand 
> the reasoning behind the elvis operator.

The principle of least astonishment indicates we should do what the 
lowering does:


expr1 ?: expr2

==>

(x => x ? x : expr2)(expr1)

An approach that does things any differently would have a much more 
difficult time. It is understood (and expected) that other languages 
have subtly different takes on the operator.


Andrei



More information about the Digitalmars-d mailing list