Jump to page: 1 2
Thread overview
Array == and <
Apr 18, 2002
Walter
Apr 18, 2002
OddesE
Apr 18, 2002
Pavel Minayev
Apr 19, 2002
Walter
Apr 19, 2002
Pavel Minayev
Apr 18, 2002
Russ Lewis
Apr 19, 2002
Walter
Apr 18, 2002
Patrick Down
Apr 19, 2002
Walter
Apr 18, 2002
Jonathan Andrew
Apr 19, 2002
Walter
Apr 19, 2002
Pavel Minayev
Apr 19, 2002
Walter
Apr 19, 2002
Pavel Minayev
Apr 22, 2002
Roberto Mariottini
Apr 22, 2002
Walter
April 18, 2002
Ok, based on everyone's feedback, D will do the following:

==, !=, <, <=, <, >= will be, for arrays, as if the operator was done
element by element. For class objects, the Object.eq() will be called for
==, !=, and Object.cmp() for <, <=, >, >=.

Two new operators, === and !==, behave the same way as == and !=, except for arrays and class objects. For those, they compare the references.

I'll try to get all this implemented in the next update.

-Walter


April 18, 2002
"Walter" <walter@digitalmars.com> wrote in message news:a9mus4$2u8a$1@digitaldaemon.com...
> Ok, based on everyone's feedback, D will do the following:
>
> ==, !=, <, <=, <, >= will be, for arrays, as if the operator was done
> element by element. For class objects, the Object.eq() will be called for
> ==, !=, and Object.cmp() for <, <=, >, >=.
>
> Two new operators, === and !==, behave the same way as == and !=, except
for
> arrays and class objects. For those, they compare the references.
>
> I'll try to get all this implemented in the next update.
>
> -Walter
>

Very cool!


--
Stijn
OddesE_XYZ@hotmail.com
http://OddesE.cjb.net
_________________________________________________
Remove _XYZ from my address when replying by mail



April 18, 2002
"Walter" <walter@digitalmars.com> wrote in message news:a9mus4$2u8a$1@digitaldaemon.com...

> Ok, based on everyone's feedback, D will do the following:
>
> ==, !=, <, <=, <, >= will be, for arrays, as if the operator was done
> element by element. For class objects, the Object.eq() will be called for
> ==, !=, and Object.cmp() for <, <=, >, >=.

And what if arrays are of different length? Operator == returns false? And for operators < and >, is the array, that is longer, truncated?

> Two new operators, === and !==, behave the same way as == and !=, except
for
> arrays and class objects. For those, they compare the references.
>
> I'll try to get all this implemented in the next update.

GREAT!


April 18, 2002
Walter wrote:

> Ok, based on everyone's feedback, D will do the following:
>
> ==, !=, <, <=, <, >= will be, for arrays, as if the operator was done
> element by element. For class objects, the Object.eq() will be called for
> ==, !=, and Object.cmp() for <, <=, >, >=.
>
> Two new operators, === and !==, behave the same way as == and !=, except for arrays and class objects. For those, they compare the references.
>
> I'll try to get all this implemented in the next update.

Great!  Two questions, though:

1) For multidimensional arrays, is the comparison element-by-element done with operator== or operator===?  That is, is it:

2) It sounds like === and !== are valid comparison operators for non-array, non-Object types.  Is there a reason for that?

--
The Villagers are Online! villagersonline.com

.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]


April 18, 2002
"Walter" <walter@digitalmars.com> wrote in news:a9mus4$2u8a$1@digitaldaemon.com:
> Ok, based on everyone's feedback, D will do the following:
> 
> ==, !=, <, <=, <, >= will be, for arrays, as if the operator was done
> element by element. For class objects, the Object.eq() will be called
> for ==, !=, and Object.cmp() for <, <=, >, >=.

I like this idea.  My one suggestion would be that since eq and cmp
( and possibly other member functions in the future ) have a special
purpose you do something that make the stand out from other member
functions.   For example: _eq_() _cmp_() or EQ() CMP()
Of course you could just leave it to the editor's syntax hilighter. :)



April 18, 2002
Walter wrote:

> Ok, based on everyone's feedback, D will do the following:
>
> ==, !=, <, <=, <, >= will be, for arrays, as if the operator was done
> element by element. For class objects, the Object.eq() will be called for
> ==, !=, and Object.cmp() for <, <=, >, >=.
>
> Two new operators, === and !==, behave the same way as == and !=, except for arrays and class objects. For those, they compare the references.
>
> I'll try to get all this implemented in the next update.
>
> -Walter

Sounds terrific! No more strcmp()! Two quick questions though:

1.) Do the above rules apply to structs also? i.e. == compares each element, === compares references?

2.) Has consensus been reached on whether object/array assignment will be by value or reference?

 Thanks,
    Jon

April 19, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message news:a9n0uo$30fh$1@digitaldaemon.com...
> "Walter" <walter@digitalmars.com> wrote in message news:a9mus4$2u8a$1@digitaldaemon.com...
>
> > Ok, based on everyone's feedback, D will do the following:
> >
> > ==, !=, <, <=, <, >= will be, for arrays, as if the operator was done element by element. For class objects, the Object.eq() will be called
for
> > ==, !=, and Object.cmp() for <, <=, >, >=.
>
> And what if arrays are of different length? Operator == returns false? And for operators < and >, is the array, that is longer, truncated?

Good question. If the array lengths are different, the arrays are compared up to the shorter of the two lengths. If the compare is equal, then the shorter array is declared the "less than" array. This is the rule for sorting strings, so I just generalized it to arrays.


April 19, 2002
"Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CBF0900.8F34E4C9@deming-os.org...
> 1) For multidimensional arrays, is the comparison element-by-element done
with
> operator== or operator===?  That is, is it:

The rule is it is evaluated as if == were applied to each element. Thus, it recursively applies to multidimensional arrays.

> 2) It sounds like === and !== are valid comparison operators for
non-array,
> non-Object types.

Yes.

>  Is there a reason for that?

Looking to the future with generic programming.



April 19, 2002
"Patrick Down" <pat@codemoon.com> wrote in message news:Xns91F489D545974patcodemooncom@63.105.9.61...
> I like this idea.  My one suggestion would be that since eq and cmp
> ( and possibly other member functions in the future ) have a special
> purpose you do something that make the stand out from other member
> functions.   For example: _eq_() _cmp_() or EQ() CMP()

Pretty much all the member functions of Object have special purposes. I've always thought the Python approach of __xxx__ as the special names was ugly <g>. Those kinds of names should be for extensions.


April 19, 2002
"Jonathan Andrew" <jon@ece.arizona.edu> wrote in message news:3CBF2F35.51F2047A@ece.arizona.edu...
> 1.) Do the above rules apply to structs also? i.e. == compares each
element,
> === compares references?

Good question. I don't know. At the moment, structs always compare using a bit compare of the contents.

> 2.) Has consensus been reached on whether object/array assignment will be
by
> value or reference?

By reference. By value is too expensive.


« First   ‹ Prev
1 2