D - Array == and <
- Walter (8/8) Apr 18 2002 Ok, based on everyone's feedback, D will do the following:
- OddesE (10/18) Apr 18 2002 for
- Pavel Minayev (6/13) Apr 18 2002 And what if arrays are of different length? Operator == returns false?
- Walter (7/16) Apr 18 2002 for
- Pavel Minayev (4/10) Apr 18 2002 I was hoping you'll say this... great! This practically eliminates
- Russ Lewis (11/18) Apr 18 2002 Great! Two questions, though:
- Walter (8/13) Apr 18 2002 with
- Patrick Down (7/12) Apr 18 2002 I like this idea. My one suggestion would be that since eq and cmp
- Walter (5/9) Apr 18 2002 Pretty much all the member functions of Object have special purposes. I'...
- Jonathan Andrew (8/16) Apr 18 2002 Sounds terrific! No more strcmp()! Two quick questions though:
- Walter (7/11) Apr 18 2002 element,
- Pavel Minayev (6/17) Apr 18 2002 And what's the reason of comparing structs references? They aren't
- Walter (5/12) Apr 18 2002 a = b[]; // assign by reference
- Pavel Minayev (4/7) Apr 19 2002 Okay, I see. But since =, ~ and ~= do a copy, indexing is the only
- Roberto Mariottini (7/10) Apr 22 2002 Is it possible to write simply:
- Walter (3/8) Apr 22 2002 Yes.
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 !=, exceptforarrays and class objects. For those, they compare the references. I'll try to get all this implemented in the next update. -WalterVery 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 !=, exceptforarrays 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...forOk, 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 calledGood 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.==, !=, 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?
Apr 18 2002
"Walter" <walter digitalmars.com> wrote in message news:a9nqfr$1n35$1 digitaldaemon.com...I was hoping you'll say this... great! This practically eliminates the need in cmp() and memcmp().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 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 donewithoperator== 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 fornon-array,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. -WalterSounds 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 eachelement,=== 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 bebyvalue 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...And what's the reason of comparing structs references? They aren't on heap anyhow...1.) Do the above rules apply to structs also? i.e. == compares eachelement,=== compares references?Good question. I don't know. At the moment, structs always compare using a bit compare of the contents.be2.) Has consensus been reached on whether object/array assignment willbyBut arrays are copy-on-write, or am I wrong?value or reference?By reference. By value is too expensive.
Apr 18 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:a9o3vk$pqa$1 digitaldaemon.com..."Walter" <walter digitalmars.com> wrote in messagea = b[]; // assign by reference a[] = b[]; // assign by copy a[3] = 4; // changes a[3] in place (no copy on write)be2.) Has consensus been reached on whether object/array assignment willbyBut arrays are copy-on-write, or am I wrong?value or reference?By reference. By value is too expensive.
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 referenceIs it possible to write simply: a = b; // assign by reference I don't like the a = b[] syntax.a[] = b[]; // assign by copyGood.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...Yes.a = b[]; // assign by referenceIs it possible to write simply: a = b; // assign by reference
Apr 22 2002