July 12, 2012
On 12/07/2012 19:32, Andrei Alexandrescu wrote:
> On 7/12/12 12:24 PM, Daniel Murphy wrote:
>> "Jonas Drewsen"<jdrewsen@nospam.com> wrote in message
>> news:zwtvliaunccmtwmabxfz@forum.dlang.org...
>>>
>>> auto a = foo ?? new Foo();
>>>
>>> is short for:
>>>
>>> auto a = foo is null ? new Foo() : foo;
>>>
>>> /Jonas
>>>
>>
>> Yeah, I've been planning to try and get this into D one day. Probably
>> something like:
>> (a ?: b) -> (auto __tmp = a, __tmp ? __tmp : b)
>
> gcc used to have that extension and they dropped it...
>
> Andrei
>

Do you know why ? It have been useful to me in languages that support it.
July 12, 2012
On Thursday, 12 July 2012 at 17:35:05 UTC, Alex Rønne Petersen wrote:
> But on the other hand, C# has had it from day one and it's still widely used and encouraged today:

It has been introduced in C# 2.0 and quickly gained high popularity.
July 12, 2012
On 7/12/12 2:37 PM, deadalnix wrote:
> On 12/07/2012 19:32, Andrei Alexandrescu wrote:
>> On 7/12/12 12:24 PM, Daniel Murphy wrote:
>>> Yeah, I've been planning to try and get this into D one day. Probably
>>> something like:
>>> (a ?: b) -> (auto __tmp = a, __tmp ? __tmp : b)
>>
>> gcc used to have that extension and they dropped it...
>>
>> Andrei
>>
>
> Do you know why ? It have been useful to me in languages that support it.

I apparently misspoke. Here's the search: http://goo.gl/zjKiJ

Andrei
July 12, 2012
On Thursday, July 12, 2012 20:37:14 deadalnix wrote:
> Do you know why ? It have been useful to me in languages that support it.

My guess would be that it didn't get used much precisely because it was an extension. Most programmers don't use language extensions. They probably don't even know that they exist in most cases, and they're often a bad idea to use, because they aren't cross platform. But if it's built into the language (as it is with C#), then a lot more programmers know about it and are more comfortable with using it, so it gets used a lot more.

- Jonathan M Davis
July 12, 2012
On 07/12/2012 09:03 PM, Andrei Alexandrescu wrote:
> On 7/12/12 2:37 PM, deadalnix wrote:
>> On 12/07/2012 19:32, Andrei Alexandrescu wrote:
>>> On 7/12/12 12:24 PM, Daniel Murphy wrote:
>>>> Yeah, I've been planning to try and get this into D one day. Probably
>>>> something like:
>>>> (a ?: b) -> (auto __tmp = a, __tmp ? __tmp : b)
>>>
>>> gcc used to have that extension and they dropped it...
>>>
>>> Andrei
>>>
>>
>> Do you know why ? It have been useful to me in languages that support it.
>
> I apparently misspoke. Here's the search: http://goo.gl/zjKiJ
>
> Andrei

You might have had in mind the <? and >? operators.
July 12, 2012
>> Yeah, I've been planning to try and get this into D one day.  Probably
>> something like:
>> (a ?: b) ->  (auto __tmp = a, __tmp ? __tmp : b)
>
> gcc used to have that extension and they dropped it...

But GCC can't control the C++ language spec. Naturally there is a reluctance to add nonstandard features. It's a successful feature in C#, however, and a lot of people (including me) have also been pestering the C# crew for "null dot" (for safely calling methods on object references that might be null.)

I don't see why you would use ?: instead of ??, though.
July 12, 2012
On 7/12/12 4:49 PM, David Piepgrass wrote:
>>> Yeah, I've been planning to try and get this into D one day. Probably
>>> something like:
>>> (a ?: b) -> (auto __tmp = a, __tmp ? __tmp : b)
>>
>> gcc used to have that extension and they dropped it...
>
> But GCC can't control the C++ language spec. Naturally there is a
> reluctance to add nonstandard features. It's a successful feature in C#,
> however, and a lot of people (including me) have also been pestering the
> C# crew for "null dot" (for safely calling methods on object references
> that might be null.)
>
> I don't see why you would use ?: instead of ??, though.

I think we can add coalesce() with any number of lazy arguments that returns the leftmost argument that is nonzero. It's a useful function but not frequent enough to warrant an operator.

Andrei
July 13, 2012
On 12/07/2012 22:49, David Piepgrass wrote:
>>> Yeah, I've been planning to try and get this into D one day. Probably
>>> something like:
>>> (a ?: b) -> (auto __tmp = a, __tmp ? __tmp : b)
>>
>> gcc used to have that extension and they dropped it...
>
> But GCC can't control the C++ language spec. Naturally there is a
> reluctance to add nonstandard features. It's a successful feature in C#,
> however, and a lot of people (including me) have also been pestering the
> C# crew for "null dot" (for safely calling methods on object references
> that might be null.)
>
> I don't see why you would use ?: instead of ??, though.

Well C# does use ?? but ?: seems to me used in more languages.
July 13, 2012
"David Piepgrass" , dans le message (digitalmars.D:172164), a écrit :
>>> Yeah, I've been planning to try and get this into D one day.
>>> Probably
>>> something like:
>>> (a ?: b) ->  (auto __tmp = a, __tmp ? __tmp : b)
>>
>> gcc used to have that extension and they dropped it...
> 
> But GCC can't control the C++ language spec. Naturally there is a reluctance to add nonstandard features. It's a successful feature in C#, however, and a lot of people (including me) have also been pestering the C# crew for "null dot" (for safely calling methods on object references that might be null.)
> 
> I don't see why you would use ?: instead of ??, though.

Because ?: is the ternary conditionnal operator with missing second operand.

a ?: b // or maybe a ? : b
is just a short hand for
a ? a : b
(except a is evaluated only once).
July 13, 2012
On Thursday, 12 July 2012 at 22:36:19 UTC, Andrei Alexandrescu wrote:
> On 7/12/12 4:49 PM, David Piepgrass wrote:
>>>> Yeah, I've been planning to try and get this into D one day. Probably
>>>> something like:
>>>> (a ?: b) -> (auto __tmp = a, __tmp ? __tmp : b)
>>>
>>> gcc used to have that extension and they dropped it...
>>
>> But GCC can't control the C++ language spec. Naturally there is a
>> reluctance to add nonstandard features. It's a successful feature in C#,
>> however, and a lot of people (including me) have also been pestering the
>> C# crew for "null dot" (for safely calling methods on object references
>> that might be null.)
>>
>> I don't see why you would use ?: instead of ??, though.
>
> I think we can add coalesce() with any number of lazy arguments that returns the leftmost argument that is nonzero. It's a useful function but not frequent enough to warrant an operator.

I Agree. Looking at the Groovy link from Christophe I noticed their Safe Navigation Operator ?.

Basicly it returns the final value in a dereference chain or null if any objects in the chain are null:

// a is null if user or address or street is null. No exception thrown.
auto a = user?.address?.street;

This is a very nice operator that would be tricky to implement as a function or template.

/Jonas