Project Elvis
MrSmith
mrsmith33 at yandex.ru
Sun Nov 5 16:32:13 UTC 2017
On Monday, 30 October 2017 at 19:46:54 UTC, Andrei Alexandrescu
wrote:
>> 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
I may add that the same logic is used in .get(key, defaultValue)
method of Associative Arrays
More information about the Digitalmars-d
mailing list