D - Array == and <
- "Walter" <walter digitalmars.com> Apr 18 2002
- "OddesE" <OddesE_XYZ hotmail.com> Apr 18 2002
- "Pavel Minayev" <evilone omen.ru> Apr 18 2002
- "Walter" <walter digitalmars.com> Apr 18 2002
- "Pavel Minayev" <evilone omen.ru> Apr 18 2002
- Russ Lewis <spamhole-2001-07-16 deming-os.org> Apr 18 2002
- "Walter" <walter digitalmars.com> Apr 18 2002
- Patrick Down <pat codemoon.com> Apr 18 2002
- "Walter" <walter digitalmars.com> Apr 18 2002
- Jonathan Andrew <jon ece.arizona.edu> Apr 18 2002
- "Walter" <walter digitalmars.com> Apr 18 2002
- "Pavel Minayev" <evilone omen.ru> Apr 18 2002
- "Walter" <walter digitalmars.com> Apr 18 2002
- "Pavel Minayev" <evilone omen.ru> Apr 19 2002
- Roberto Mariottini <rmariottini lycosmail.com> Apr 22 2002
- "Walter" <walter digitalmars.com> Apr 22 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
Apr 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
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
Apr 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
arrays and class objects. For those, they compare the references. I'll try to get all this implemented in the next update.
GREAT!
Apr 18 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
==, !=, 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.
Apr 18 2002
"Walter" <walter digitalmars.com> wrote in message news:a9nqfr$1n35$1 digitaldaemon.com...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.
I was hoping you'll say this... great! This practically eliminates the need in cmp() and memcmp().
Apr 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))) ]
Apr 18 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
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-Object types.
Yes.Is there a reason for that?
Looking to the future with generic programming.
Apr 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. :)
Apr 18 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.
Apr 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
Apr 18 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
=== 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
value or reference?
By reference. By value is too expensive.
Apr 18 2002
"Walter" <walter digitalmars.com> wrote in message news:a9nqs2$1qmk$1 digitaldaemon.com..."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
=== compares references?
Good question. I don't know. At the moment, structs always compare using a bit compare of the contents.
And what's the reason of comparing structs references? They aren't on heap anyhow...2.) Has consensus been reached on whether object/array assignment will
byvalue or reference?
By reference. By value is too expensive.
But arrays are copy-on-write, or am I wrong?
Apr 18 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:a9o3vk$pqa$1 digitaldaemon.com..."Walter" <walter digitalmars.com> wrote in message2.) Has consensus been reached on whether object/array assignment will
byvalue or reference?
a = b[]; // assign by reference a[] = b[]; // assign by copy a[3] = 4; // changes a[3] in place (no copy on write)
Apr 18 2002
"Walter" <walter digitalmars.com> wrote in message news:a9obak$1c9s$1 digitaldaemon.com...a = b[]; // assign by reference a[] = b[]; // assign by copy a[3] = 4; // changes a[3] in place (no copy on write)
Okay, I see. But since =, ~ and ~= do a copy, indexing is the only operation that doesn't - so it is very close to copy-on-write.
Apr 19 2002
In article <a9obak$1c9s$1 digitaldaemon.com>, Walter says...a = b[]; // assign by reference
Is it possible to write simply: a = b; // assign by reference I don't like the a = b[] syntax.a[] = b[]; // assign by copy
Good.a[3] = 4; // changes a[3] in place (no copy on write)
Obviously. Ciao
Apr 22 2002
"Roberto Mariottini" <rmariottini lycosmail.com> wrote in message news:aa167d$306l$1 digitaldaemon.com...In article <a9obak$1c9s$1 digitaldaemon.com>, Walter says...a = b[]; // assign by reference
a = b; // assign by reference
Yes.
Apr 22 2002









"OddesE" <OddesE_XYZ hotmail.com> 