Re: "is" operator for structures?

2012-05-09 Thread Jacob Carlborg

On 2012-05-10 00:05, H. S. Teoh wrote:

On Wed, May 09, 2012 at 05:04:59PM -0400, Steven Schveighoffer wrote:



Is there a unicode glyph for fist pump? :)

[...]

U+270A?

:-)


Haha :)


--
/Jacob Carlborg


Re: "is" operator for structures?

2012-05-09 Thread Gor Gyolchanyan
I think it would be a unary prefix operator, which returns the
operand's copy, but with double the storage, having the second half -
wasted. :-D

On Thu, May 10, 2012 at 2:33 AM, Matt Soucy  wrote:
> On 05/09/2012 06:05 PM, H. S. Teoh wrote:
>>
>> On Wed, May 09, 2012 at 05:04:59PM -0400, Steven Schveighoffer wrote:
>>>
>>> On Wed, 09 May 2012 16:25:35 -0400, Jacob Carlborg  wrote:
>>>
 On 2012-05-09 18:13, Steven Schveighoffer wrote:

> This also works too:
>
> int opBinary(string s: "booya!")(...)
>

 We could create new operators :)
>>>
>>>
>>> Is there a unicode glyph for fist pump? :)
>>
>> [...]
>>
>> U+270A?
>>
>> :-)
>>
>>
>> T
>>
>
> I can only imagine what a fistpump operator would do...
> Also, this is my favorite new glyph.



-- 
Bye,
Gor Gyolchanyan.


Re: "is" operator for structures?

2012-05-09 Thread Matt Soucy

On 05/09/2012 06:05 PM, H. S. Teoh wrote:

On Wed, May 09, 2012 at 05:04:59PM -0400, Steven Schveighoffer wrote:

On Wed, 09 May 2012 16:25:35 -0400, Jacob Carlborg  wrote:


On 2012-05-09 18:13, Steven Schveighoffer wrote:


This also works too:

int opBinary(string s: "booya!")(...)



We could create new operators :)


Is there a unicode glyph for fist pump? :)

[...]

U+270A?

:-)


T



I can only imagine what a fistpump operator would do...
Also, this is my favorite new glyph.


Re: "is" operator for structures?

2012-05-09 Thread H. S. Teoh
On Wed, May 09, 2012 at 05:04:59PM -0400, Steven Schveighoffer wrote:
> On Wed, 09 May 2012 16:25:35 -0400, Jacob Carlborg  wrote:
> 
> >On 2012-05-09 18:13, Steven Schveighoffer wrote:
> >
> >>This also works too:
> >>
> >>int opBinary(string s: "booya!")(...)
> >>
> >
> >We could create new operators :)
> 
> Is there a unicode glyph for fist pump? :)
[...]

U+270A?

:-)


T

-- 
"I speak better English than this villain Bush" -- Mohammed Saeed al-Sahaf, 
Iraqi Minister of Information


Re: "is" operator for structures?

2012-05-09 Thread Steven Schveighoffer

On Wed, 09 May 2012 16:25:35 -0400, Jacob Carlborg  wrote:


On 2012-05-09 18:13, Steven Schveighoffer wrote:


This also works too:

int opBinary(string s: "booya!")(...)



We could create new operators :)


Is there a unicode glyph for fist pump? :)

-Steve


Re: "is" operator for structures?

2012-05-09 Thread Jacob Carlborg

On 2012-05-09 18:13, Steven Schveighoffer wrote:


This also works too:

int opBinary(string s: "booya!")(...)



We could create new operators :)


--
/Jacob Carlborg


Re: "is" operator for structures?

2012-05-09 Thread Gor Gyolchanyan
Btw, I noticed how classes have two different comparison operators
(one for the reference and one for the object), while they have only
one assignment operator (for the reference only),
I think having two assignment operators would be very good for a
number of cases. Combined with a "final class" declaration it would
essentially be a reference type struct with a default constructor.
I've wanted such a thing for a long time now.

On Wed, May 9, 2012 at 8:48 PM, Steven Schveighoffer
 wrote:
> On Wed, 09 May 2012 12:21:05 -0400, Gor Gyolchanyan
>  wrote:
>
>> If "is" was overloadable, one could make a legitimate reference types
>> via structs. The opAssign would change the reference, opEquals would
>> call the opEquals of the referred object, opBinary(string op : `is`)
>> would compare the references... Just like classes.
>
>
> Yes, this is probably the only legitimate use case.  I'm not sure how to
> make it work, exactly.  But the functionality of 'is' should not be
> affected, it's too valuable the way it is to change it.
>
> -Steve



-- 
Bye,
Gor Gyolchanyan.


Re: "is" operator for structures?

2012-05-09 Thread Gor Gyolchanyan
Yeah, that's what I did. I replaced it with opEquals(typeof(null)).

On Wed, May 9, 2012 at 8:45 PM, Steven Schveighoffer
 wrote:
> On Wed, 09 May 2012 12:17:30 -0400, Gor Gyolchanyan
>  wrote:
>
>> I didn't know structs actually have an "is" operator. Good to know,
>> there's a way to memcmp them this way.
>> But being able to overload it wouldn't do any damage. The overloader
>> of "is" should clearly know, that "is" is an identity check and not an
>> arbitrary domain-specific equality check.
>> Overloading "is" gives a syntax sugar for nullable structures and an
>> optimization opportunity for large ones (for example a CRC checksum
>> comparison).
>
>
> The fact that it's not overloadable is useful in many situations.  There are
> certain cases you are truly looking for physical equality, and not logical
> equality.
>
> Generally, if you want logical equality, use opEquals.
>
> -Steve



-- 
Bye,
Gor Gyolchanyan.


Re: "is" operator for structures?

2012-05-09 Thread Steven Schveighoffer
On Wed, 09 May 2012 12:21:05 -0400, Gor Gyolchanyan  
 wrote:



If "is" was overloadable, one could make a legitimate reference types
via structs. The opAssign would change the reference, opEquals would
call the opEquals of the referred object, opBinary(string op : `is`)
would compare the references... Just like classes.


Yes, this is probably the only legitimate use case.  I'm not sure how to  
make it work, exactly.  But the functionality of 'is' should not be  
affected, it's too valuable the way it is to change it.


-Steve


Re: "is" operator for structures?

2012-05-09 Thread Steven Schveighoffer
On Wed, 09 May 2012 12:17:30 -0400, Gor Gyolchanyan  
 wrote:



I didn't know structs actually have an "is" operator. Good to know,
there's a way to memcmp them this way.
But being able to overload it wouldn't do any damage. The overloader
of "is" should clearly know, that "is" is an identity check and not an
arbitrary domain-specific equality check.
Overloading "is" gives a syntax sugar for nullable structures and an
optimization opportunity for large ones (for example a CRC checksum
comparison).


The fact that it's not overloadable is useful in many situations.  There  
are certain cases you are truly looking for physical equality, and not  
logical equality.


Generally, if you want logical equality, use opEquals.

-Steve


Re: "is" operator for structures?

2012-05-09 Thread Gor Gyolchanyan
If "is" was overloadable, one could make a legitimate reference types
via structs. The opAssign would change the reference, opEquals would
call the opEquals of the referred object, opBinary(string op : `is`)
would compare the references... Just like classes.

On Wed, May 9, 2012 at 8:13 PM, Steven Schveighoffer
 wrote:
> On Wed, 09 May 2012 10:13:01 -0400, bearophile 
> wrote:
>
>> Gor Gyolchanyan:
>>
>>> Because the opBinary [...]
>>
>>
>> Thank for your answer, but I don't carte of "why" the D compiler accepts
>> that. I only care about the D compiler statically refusing that.
>
>
> This also works too:
>
> int opBinary(string s: "booya!")(...)
>
> or this too:
>
> int opBinry(string s: "+")(...)
>
> opBinary is a valid symbol, and as a valid symbol, it is a valid function,
> no matter whether the compiler calls it in a special way.
>
> I don't think it is a terrible thing, and I think statically disallowing
> that would be a worse idea.
>
> And to answer the OP, 'is' is special, it signals a bitwise compare, no
> matter what the contents of the type being compared.
>
> That being said, I understand why you want to do that.  I don't see any way
> around it.
>
> -Steve



-- 
Bye,
Gor Gyolchanyan.


Re: "is" operator for structures?

2012-05-09 Thread Gor Gyolchanyan
I didn't know structs actually have an "is" operator. Good to know,
there's a way to memcmp them this way.
But being able to overload it wouldn't do any damage. The overloader
of "is" should clearly know, that "is" is an identity check and not an
arbitrary domain-specific equality check.
Overloading "is" gives a syntax sugar for nullable structures and an
optimization opportunity for large ones (for example a CRC checksum
comparison).

On Wed, May 9, 2012 at 8:13 PM, Steven Schveighoffer
 wrote:
> On Wed, 09 May 2012 10:13:01 -0400, bearophile 
> wrote:
>
>> Gor Gyolchanyan:
>>
>>> Because the opBinary [...]
>>
>>
>> Thank for your answer, but I don't carte of "why" the D compiler accepts
>> that. I only care about the D compiler statically refusing that.
>
>
> This also works too:
>
> int opBinary(string s: "booya!")(...)
>
> or this too:
>
> int opBinry(string s: "+")(...)
>
> opBinary is a valid symbol, and as a valid symbol, it is a valid function,
> no matter whether the compiler calls it in a special way.
>
> I don't think it is a terrible thing, and I think statically disallowing
> that would be a worse idea.
>
> And to answer the OP, 'is' is special, it signals a bitwise compare, no
> matter what the contents of the type being compared.
>
> That being said, I understand why you want to do that.  I don't see any way
> around it.
>
> -Steve



-- 
Bye,
Gor Gyolchanyan.


Re: "is" operator for structures?

2012-05-09 Thread Steven Schveighoffer
On Wed, 09 May 2012 10:13:01 -0400, bearophile   
wrote:



Gor Gyolchanyan:


Because the opBinary [...]


Thank for your answer, but I don't carte of "why" the D compiler accepts  
that. I only care about the D compiler statically refusing that.


This also works too:

int opBinary(string s: "booya!")(...)

or this too:

int opBinry(string s: "+")(...)

opBinary is a valid symbol, and as a valid symbol, it is a valid function,  
no matter whether the compiler calls it in a special way.


I don't think it is a terrible thing, and I think statically disallowing  
that would be a worse idea.


And to answer the OP, 'is' is special, it signals a bitwise compare, no  
matter what the contents of the type being compared.


That being said, I understand why you want to do that.  I don't see any  
way around it.


-Steve


Re: "is" operator for structures?

2012-05-09 Thread Don Clugston

On 09/05/12 16:13, bearophile wrote:

Gor Gyolchanyan:


Because the opBinary [...]


Thank for your answer, but I don't carte of "why" the D compiler accepts
that. I only care about the D compiler statically refusing that.

Bye,
bearophile


I think you're asking for opBinary to be a keyword.
If it were statically rejected, surely you'll also want to have:

void opBinary(string xx, int x) {}

rejected as well. Along with a multitude of other things.


Re: "is" operator for structures?

2012-05-09 Thread bearophile

Gor Gyolchanyan:


Because the opBinary [...]


Thank for your answer, but I don't carte of "why" the D compiler 
accepts that. I only care about the D compiler statically 
refusing that.


Bye,
bearophile


Re: "is" operator for structures?

2012-05-09 Thread Gor Gyolchanyan
Because the opBinary is a perfectly valid method. The inability to
overload "is" only affects the rewrite of "A is B" to
"A.opBinart!`is`(B)".

On Wed, May 9, 2012 at 5:46 PM, bearophile  wrote:
> Gor Gyolchanyan:
>
>
>> My question is, why not allow is operator to be overloadable for
>> structures?
>
>
> Or why the bad D compiler doesn't statically refuse the code like:
>
>
>>    bool opBinary(string op : "is")(typeof(null))
>
>
> Bye,
> bearophile
>



-- 
Bye,
Gor Gyolchanyan.


Re: "is" operator for structures?

2012-05-09 Thread bearophile

Gor Gyolchanyan:

My question is, why not allow is operator to be overloadable 
for structures?


Or why the bad D compiler doesn't statically refuse the code like:


bool opBinary(string op : "is")(typeof(null))


Bye,
bearophile