July 11, 2012
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 integrated with the concurrency somehow or used in some other area.
July 11, 2012
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 value from c
>
> maybe this could be integrated with the concurrency somehow or used in
> some other area.

This is not something important enough to warrant a language feature in my opinion. And certainly not one that results in a Phobos dependency.

-- 
Alex Rønne Petersen
alex@lycus.org
http://lycus.org
July 11, 2012
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 write "!!val" than "cast(bool)val".

This is only moderately useful, as 90% of the time, the cast occurs in a if/while/for, where implicit casts to bool are legal, but still:

----
import std.stdio;

struct S
{
  int v;
  bool opCast() {return cast(bool)v;}
}

void foo(bool b){}

void main()
{
  S s = S(5);
  //bool b = s; //Error: cannot implicitly convert expression (s) of type S to bool
  bool b = !!s; //This is valid though, and shorter than //bool b = cast(bool)s;
  if(s) //But it works inside a if anyways
    ...

  foo(!!s); //Call foo with s as boolean
}
----

I've seen this used a lot in c++. explicit casts did not exist prior to c++11. To allow casting to bool while avoiding the dangers of implicit casts, one design patter was to define "only" operator"!", and use !!val as an alternative to casting to bool.

After you've seen it a few times, it feels natural, as if it was an operator of itself.

I wouldn't be surprised if this is happening in D, so I don't think "!!" can be taken for anything.
July 11, 2012
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 surprised if this is happening in D, so I don't think "!!"
> can be taken for anything.

This is about binary x!!y, not unary !!x.



July 11, 2012
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 message e along channel c
>> c?x assigns to variable x the value from c
>>
>> maybe this could be integrated with the concurrency somehow or used in
>> some other area.
>
> This is not something important enough to warrant a language feature in
> my opinion. And certainly not one that results in a Phobos dependency.
>

Making the operator overloadable does not result in a Phobos dependency.
July 11, 2012
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 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 integrated with the concurrency somehow or used in
>>> some other area.
>>
>> This is not something important enough to warrant a language feature in
>> my opinion. And certainly not one that results in a Phobos dependency.
>>
>
> Making the operator overloadable does not result in a Phobos dependency.

Yes, I know.

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.

-- 
Alex Rønne Petersen
alex@lycus.org
http://lycus.org
July 11, 2012
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 ?
July 11, 2012
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: "look, a nice operator! maybe could be useful if the D community knows about it!".

Do you really see in my original post a request for defining it?


July 11, 2012
>>>> 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)
July 12, 2012
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

« First   ‹ Prev
1 2 3 4
Top | Discussion index | About this forum | D home