Re: just an idea (!! operator)

2012-07-13 Thread David Piepgrass
On Friday, 13 July 2012 at 09:49:22 UTC, monarch_dodra wrote: I don't know much about C#, but in C#, isn't EVERYTHING a reference type? Meaning it always makes sense to check if "myobject is null". No, C# has value types (enums, primitives, and user-defined types) which are not nullable. The n

Re: just an idea (!! operator)

2012-07-13 Thread Christophe Travert
"Roman D. Boiko" , dans le message (digitalmars.D:172259), a écrit : > On Friday, 13 July 2012 at 13:46:10 UTC, David Nadlinger wrote: >> I guess that this operator is only really worth it in languages >> where every type is nullable, though. >> >> David > > It might mean identity (return the argu

Re: just an idea (!! operator)

2012-07-13 Thread Roman D. Boiko
On Friday, 13 July 2012 at 13:46:10 UTC, David Nadlinger wrote: I guess that this operator is only really worth it in languages where every type is nullable, though. David It might mean identity (return the argument unchanged) for value types.

Re: just an idea (!! operator)

2012-07-13 Thread David Nadlinger
On Friday, 13 July 2012 at 12:51:07 UTC, Jacob Carlborg wrote: On 2012-07-13 11:24, Jonas Drewsen wrote: // a is null if user or address or street is null. No exception thrown. auto a = user?.address?.street; But what would the static type of "a" be? I don't think there is much doubt in thi

Re: just an idea (!! operator)

2012-07-13 Thread Jacob Carlborg
On 2012-07-13 11:24, Jonas Drewsen wrote: 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. N

Re: just an idea (!! operator)

2012-07-13 Thread deadalnix
On 13/07/2012 13:31, Jonas Drewsen wrote: On Friday, 13 July 2012 at 09:49:22 UTC, monarch_dodra wrote: I don't know much about C#, but in C#, isn't EVERYTHING a reference type? Meaning it always makes sense to check if "myobject is null". I'm still no expert in D either, but what would(should)

Re: just an idea (!! operator)

2012-07-13 Thread Christophe Travert
"Jonas Drewsen" , dans le message (digitalmars.D:172242), a écrit : > Can you identify any ambiguity with an ?. operator. ? could be the begining of a ternary operator, and . the module scope indicator, or the beginning of a (badly) written float number. Both case can be disambiguated by the pre

Re: just an idea (!! operator)

2012-07-13 Thread Jonas Drewsen
On Friday, 13 July 2012 at 09:49:22 UTC, monarch_dodra wrote: I don't know much about C#, but in C#, isn't EVERYTHING a reference type? Meaning it always makes sense to check if "myobject is null". I'm still no expert in D either, but what would(should) happen if you tried to call ?: or ?. on

Re: just an idea (!! operator)

2012-07-13 Thread monarch_dodra
I don't know much about C#, but in C#, isn't EVERYTHING a reference type? Meaning it always makes sense to check if "myobject is null". I'm still no expert in D either, but what would(should) happen if you tried to call ?: or ?. on a value type? Writing "s is null" gives "Error: incompatible

Re: just an idea (!! operator)

2012-07-13 Thread Jonas Drewsen
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 dropp

Re: just an idea (!! operator)

2012-07-13 Thread Christophe Travert
"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 ca

Re: just an idea (!! operator)

2012-07-12 Thread deadalnix
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

Re: just an idea (!! operator)

2012-07-12 Thread Andrei Alexandrescu
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

Re: just an idea (!! operator)

2012-07-12 Thread David Piepgrass
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 featu

Re: just an idea (!! operator)

2012-07-12 Thread Timon Gehr
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, _

Re: just an idea (!! operator)

2012-07-12 Thread Jonathan M Davis
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 tha

Re: just an idea (!! operator)

2012-07-12 Thread Andrei Alexandrescu
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

Re: just an idea (!! operator)

2012-07-12 Thread Roman D. Boiko
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.

Re: just an idea (!! operator)

2012-07-12 Thread deadalnix
On 12/07/2012 19:32, Andrei Alexandrescu wrote: On 7/12/12 12:24 PM, Daniel Murphy wrote: "Jonas Drewsen" wrote in message news:zwtvliaunccmtwmab...@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

Re: just an idea (!! operator)

2012-07-12 Thread Jacob Carlborg
On 2012-07-12 18:24, 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) We need to combine it with the assignment operator as well: Object foo; foo ?:= new Object; // only assign if "foo"

Re: just an idea (!! operator)

2012-07-12 Thread Alex Rønne Petersen
On 12-07-2012 19:32, Andrei Alexandrescu wrote: On 7/12/12 12:24 PM, Daniel Murphy wrote: "Jonas Drewsen" wrote in message news:zwtvliaunccmtwmab...@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

Re: just an idea (!! operator)

2012-07-12 Thread Andrei Alexandrescu
On 7/12/12 12:24 PM, Daniel Murphy wrote: "Jonas Drewsen" wrote in message news:zwtvliaunccmtwmab...@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

Re: just an idea (!! operator)

2012-07-12 Thread Araq
On Wednesday, 11 July 2012 at 18:21:33 UTC, David Piepgrass wrote: it is just an idea, i do not have any specific use in mind. ... But we can't base the decision solely on this fact. Then we could add a million operators to the language just because they seem neat. Actually, we could! Great

Re: just an idea (!! operator)

2012-07-12 Thread Daniel Murphy
"Jonas Drewsen" wrote in message news:zwtvliaunccmtwmab...@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

Re: just an idea (!! operator)

2012-07-12 Thread Christophe Travert
Jacob Carlborg , dans le message (digitalmars.D:172056), a écrit : > On 2012-07-12 13:35, Jonas Drewsen wrote: > >> Or the operator?? could be borrowed from c# >> >> auto a = foo ?? new Foo(); >> >> is short for: >> >> auto a = foo is null ? new Foo() : foo; >> >> /Jonas >> > > I really like that

Re: just an idea (!! operator)

2012-07-12 Thread Roman D. Boiko
On Thursday, 12 July 2012 at 12:51:38 UTC, Jacob Carlborg wrote: On 2012-07-12 13:35, Jonas Drewsen wrote: Or the operator?? could be borrowed from c# auto a = foo ?? new Foo(); is short for: auto a = foo is null ? new Foo() : foo; /Jonas I really like that operator. The existential oper

Re: just an idea (!! operator)

2012-07-12 Thread Jacob Carlborg
On 2012-07-12 13:35, Jonas Drewsen wrote: Or the operator?? could be borrowed from c# auto a = foo ?? new Foo(); is short for: auto a = foo is null ? new Foo() : foo; /Jonas I really like that operator. The existential operator, also known as the Elvis operator :) . It's available in man

Re: just an idea (!! operator)

2012-07-12 Thread Christophe Travert
Christophe Travert, dans le message (digitalmars.D:172047), a écrit : > "Jonas Drewsen" , dans le message (digitalmars.D:172039), a écrit : >> On Wednesday, 11 July 2012 at 11:18:21 UTC, akaz wrote: >>> if needed, the operator !! (double exclamation mark) could be >>> defined. >>> >>> ... >> >> O

Re: just an idea (!! operator)

2012-07-12 Thread Christophe Travert
"Jonas Drewsen" , dans le message (digitalmars.D:172039), a écrit : > On Wednesday, 11 July 2012 at 11:18:21 UTC, akaz wrote: >> if needed, the operator !! (double exclamation mark) could be >> defined. >> >> ... > > Or the operator?? could be borrowed from c# > > auto a = foo ?? new Foo(); > >

Re: just an idea (!! operator)

2012-07-12 Thread Jonas Drewsen
On Wednesday, 11 July 2012 at 11:18:21 UTC, akaz wrote: if needed, the operator !! (double exclamation mark) could be defined. ... Or the operator?? could be borrowed from c# auto a = foo ?? new Foo(); is short for: auto a = foo is null ? new Foo() : foo; /Jonas

Re: just an idea (!! operator)

2012-07-11 Thread David Piepgrass
it is just an idea, i do not have any specific use in mind. ... But we can't base the decision solely on this fact. Then we could add a million operators to the language just because they seem neat. Actually, we could! Great idea, nimrod! (inside joke)

Re: just an idea (!! operator)

2012-07-11 Thread akaz
On Wednesday, 11 July 2012 at 14:08:55 UTC, deadalnix wrote: On 11/07/2012 13:18, akaz wrote: So why do you do a proposal if this is not needed ? I did not ask for it, I only reminded that it is possible to define it "if needed". It's merely a suggestion. I was reading a book and told myself:

Re: just an idea (!! operator)

2012-07-11 Thread deadalnix
On 11/07/2012 13:18, akaz wrote: if needed, the operator !! (double exclamation mark) could be defined. it is just an idea, i do not have any specific use in mind. So why do you do a proposal if this is not needed ?

Re: just an idea (!! operator)

2012-07-11 Thread Alex Rønne Petersen
On 11-07-2012 15:42, Timon Gehr wrote: On 07/11/2012 01:33 PM, Alex Rønne Petersen wrote: On 11-07-2012 13:18, akaz wrote: if needed, the operator !! (double exclamation mark) could be defined. it is just an idea, i do not have any specific use in mind. i encountered the operator in RT operat

Re: just an idea (!! operator)

2012-07-11 Thread Timon Gehr
On 07/11/2012 01:33 PM, Alex Rønne Petersen wrote: On 11-07-2012 13:18, akaz wrote: if needed, the operator !! (double exclamation mark) could be defined. it is just an idea, i do not have any specific use in mind. i encountered the operator in RT operating systems book: c!!e sends the messag

Re: just an idea (!! operator)

2012-07-11 Thread Don Clugston
On 11/07/12 13:47, monarch_dodra wrote: On Wednesday, 11 July 2012 at 11:18:21 UTC, akaz wrote: if needed, the operator !! (double exclamation mark) could be defined. Problem is that operator"!!" is already used asa twin operator"!". This is shorthand for "is valid as bool": I wouldn't be

Re: just an idea (!! operator)

2012-07-11 Thread monarch_dodra
On Wednesday, 11 July 2012 at 11:18:21 UTC, akaz wrote: if needed, the operator !! (double exclamation mark) could be defined. Problem is that operator"!!" is already used asa twin operator"!". This is shorthand for "is valid as bool": When a type can be casted to bool, it is quicker to wri

Re: just an idea (!! operator)

2012-07-11 Thread Alex Rønne Petersen
On 11-07-2012 13:18, akaz wrote: if needed, the operator !! (double exclamation mark) could be defined. it is just an idea, i do not have any specific use in mind. i encountered the operator in RT operating systems book: c!!e sends the message e along channel c c?x assigns to variable x the va

just an idea (!! operator)

2012-07-11 Thread akaz
if needed, the operator !! (double exclamation mark) could be defined. it is just an idea, i do not have any specific use in mind. i encountered the operator in RT operating systems book: c!!e sends the message e along channel c c?x assigns to variable x the value from c maybe this could be i