Adding the ?. null verification

Ary Borenszweig via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 24 13:52:27 PDT 2014


On 6/24/14, 4:43 PM, Jacob Carlborg wrote:
> On 2014-06-24 18:52, Yota wrote:
>> On Sunday, 22 June 2014 at 08:15:45 UTC, Andrei Alexandrescu wrote:
>>> On 6/21/14, 3:38 PM, H. S. Teoh via Digitalmars-d wrote:
>>>> On Sat, Jun 21, 2014 at 03:26:45PM -0700, Andrei Alexandrescu via
>>>> Digitalmars-d wrote:
>>>>> On 6/19/14, 1:29 PM, Etienne wrote:
>>>>>> writeln(currAssignment.safeDeref.typeInfo.ident.or("meh"));
>>>>>
>>>>> "or" is really nice and terse. I think we should add that to std.
>>>>> safeDeref isn't the best choice of name.
>>>> [...]
>>>>
>>>> What's your suggestion?
>>>
>>> That we add "or" to std and find a name for safeDeref that doesn't use
>>> the word "safe" in a confusing manner. -- Andrei
>>
>> C# calls the ?? operator the "null-coalescing" operator.  I have
>> absolutely no idea why, but that does give precedence for calling it
>> "coalesce".
>
> In CoffeeScript it's called The Existential Operator. It's also known as
> The Elvis Operator.
>

And in Ruby it's just "||=". How more intuitive can it get?

a = nil
a ||= 1

The "or" that you are discussing here is just an "||" in Ruby:

b = nil || 1




More information about the Digitalmars-d mailing list