www.digitalmars.com         C & C++   DMDScript  

D - Array comparisons

reply "Walter" <walter digitalmars.com> writes:
I've been reading all the messages on string comparisons, and propose the
following:

Since <, <=, >, >= make little sense on dynamic array references, those are
by value. Introduce two new operators, === and !==, to do a by-value
comparison for arrays. Similarly, for class objects, == and != will compare
the references, and === and !== will call the equals() function in the
Object base class.
Mar 26 2002
next sibling parent reply Russell Borogove <kaleja estarcion.com> writes:
Walter wrote:
 I've been reading all the messages on string comparisons, and propose the
 following:
 
 Since <, <=, >, >= make little sense on dynamic array references, those are
 by value. Introduce two new operators, === and !==, to do a by-value
 comparison for arrays. Similarly, for class objects, == and != will compare
 the references, and === and !== will call the equals() function in the
 Object base class.
I'd strongly prefer the other way around -- use value semantics for == and !=, and reference semantics for === and !==. -Russell B
Mar 26 2002
next sibling parent reply Juarez Rudsatz <juarez correio.com> writes:
Russell Borogove <kaleja estarcion.com> wrote in
news:3CA124F2.1010802 estarcion.com: 

 Walter wrote:
 I've been reading all the messages on string comparisons, and propose
 the following:
 I'd strongly prefer the other way around
 -- use value semantics
 for == and !=, 
 and reference semantics for === and !==.
 
 -Russell B
2 votes. Programmer will need much more comparating values of arrays than references. Compare the statistics of use and choose the implementation.
Mar 26 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
"Juarez Rudsatz" <juarez correio.com> wrote in message
news:Xns91DDEEB1A3B8Ejuarezcom 63.105.9.61...

 2 votes.

 Programmer will need much more comparating values of arrays than
references.
 Compare the statistics of use and choose the implementation.
Agreed (so 3 already). However, I wouldn't really mind if it was vice versa. I just like comparison by value to be default more.
Mar 26 2002
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Russell Borogove" <kaleja estarcion.com> wrote in message
news:3CA124F2.1010802 estarcion.com...
 Walter wrote:
 Since <, <=, >, >= make little sense on dynamic array references, those
are
 by value. Introduce two new operators, === and !==, to do a by-value
 comparison for arrays. Similarly, for class objects, == and != will
compare
 the references, and === and !== will call the equals() function in the
 Object base class.
I'd strongly prefer the other way around -- use value semantics for == and !=, and reference semantics for === and !==.
That idea has great merit, but I worry that == being a reference comparison for, say, Object references, would just cause too much confusion.
Mar 26 2002
next sibling parent "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a7rq5c$1s0b$2 digitaldaemon.com...

 That idea has great merit, but I worry that == being a reference
comparison
 for, say, Object references, would just cause too much confusion.
Yep, you are right... and making semantics different for objects and arrays is probably not the best idea... Okay, then let it be ===.
Mar 27 2002
prev sibling parent reply "Immanuel Scholz" <digital-mars kutzsche.net> writes:
"Walter" <walter digitalmars.com> schrieb im Newsbeitrag
news:a7rq5c$1s0b$2 digitaldaemon.com...
 "Russell Borogove" <kaleja estarcion.com> wrote in message
 news:3CA124F2.1010802 estarcion.com...
 Walter wrote:
 Since <, <=, >, >= make little sense on dynamic array references,
those
 are
 by value. Introduce two new operators, === and !==, to do a by-value
 comparison for arrays. Similarly, for class objects, == and != will
compare
 the references, and === and !== will call the equals() function in the
 Object base class.
I'd strongly prefer the other way around -- use value semantics for == and !=, and reference semantics for === and !==.
That idea has great merit, but I worry that == being a reference
comparison
 for, say, Object references, would just cause too much confusion.
You can resolve the confusion by making == a value-comparation for objects too :-) "x === y" can become the meaning of "&x == &y" in general, so this is not confusing too... Imi
Mar 27 2002
parent reply "Sean L. Palmer" <spalmer iname.com> writes:
I would rather just write "&x == &y".  It's explicit.  It's easy.

=== is too easy to confuse with == which is already too easy to confuse with
=.

Sean

 "x === y" can become the meaning of "&x == &y" in general, so this is not
 confusing too...

 Imi
Mar 27 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Sean L. Palmer" <spalmer iname.com> wrote in message
news:a7t5g6$2k4k$1 digitaldaemon.com...

 I would rather just write "&x == &y".  It's explicit.  It's easy.

 === is too easy to confuse with == which is already too easy to confuse
with
 =.
All C/C++/D programmers should have natural immunity to confusing = with ==, and thus == and === won't be confused either =) Seriously speaking, since === will be used on arrays, I don't see why it can't be used on objects as well. Also, & is an "address of" operator, so &x will be of type Object*, and you will in fact compare addresses of references...
Mar 27 2002
parent reply "Sean L. Palmer" <spalmer iname.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a7tds3$2o9l$1 digitaldaemon.com...
 "Sean L. Palmer" <spalmer iname.com> wrote in message
 news:a7t5g6$2k4k$1 digitaldaemon.com...

 I would rather just write "&x == &y".  It's explicit.  It's easy.

 === is too easy to confuse with == which is already too easy to confuse
with
 =.
All C/C++/D programmers should have natural immunity to confusing = with
==,
 and thus == and === won't be confused either =)

 Seriously speaking, since === will be used on arrays, I don't see why it
 can't be used on objects as well.
So it's already been decided then? Well what the hell are we discussing it for?
 Also, & is an "address of" operator, so &x will be of type Object*, and
 you will in fact compare addresses of references...
Implementation detail. It will work.
Mar 28 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
"Sean L. Palmer" <spalmer iname.com> wrote in message
news:a7ungk$bp0$1 digitaldaemon.com...

 Seriously speaking, since === will be used on arrays, I don't see why it
 can't be used on objects as well.
So it's already been decided then? Well what the hell are we discussing
it
 for?
Walter decided to use it for arrays. I thought we were discussing, how to apply it to objects as well?
 Also, & is an "address of" operator, so &x will be of type Object*, and
 you will in fact compare addresses of references...
Implementation detail. It will work.
... by banning pointers to references (because & won't work on references as expected).
Mar 28 2002
prev sibling next sibling parent "Gary" <gedumer bcpl.net> writes:
Walter <walter digitalmars.com> wrote in message
news:a7r7ok$1ing$2 digitaldaemon.com...
 I've been reading all the messages on string comparisons, and propose the
 following:

 Since <, <=, >, >= make little sense on dynamic array references, those
are
 by value. Introduce two new operators, === and !==, to do a by-value
 comparison for arrays. Similarly, for class objects, == and != will
compare
 the references, and === and !== will call the equals() function in the
 Object base class.
Sounds great... when do you expect we may see it in action? Gary.
Mar 26 2002
prev sibling next sibling parent reply Juarez Rudsatz <juarez correio.com> writes:
"Walter" <walter digitalmars.com> wrote in
news:a7r7ok$1ing$2 digitaldaemon.com: 

 Since <, <=, >, >= make little sense on dynamic array references,
 those are 
 
I dont know why ? Strings comparation dont is a good example ? J.
Mar 26 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
"Juarez Rudsatz" <juarez correio.com> wrote in message
news:Xns91DDEEF3F4733juarezcom 63.105.9.61...

 Since <, <=, >, >= make little sense on dynamic array references,
 those are
I dont know why ? Strings comparation dont is a good example ?
Array _references_, not contents. When you compare strings, you compare contents.
Mar 26 2002
prev sibling next sibling parent reply "Roberto Mariottini" <rmariottini lycosmail.com> writes:
"Walter" <walter digitalmars.com> ha scritto nel messaggio
news:a7r7ok$1ing$2 digitaldaemon.com...
 I've been reading all the messages on string comparisons, and propose the
 following:

 Since <, <=, >, >= make little sense on dynamic array references, those
are
 by value. Introduce two new operators, === and !==, to do a by-value
 comparison for arrays. Similarly, for class objects, == and != will
compare
 the references, and === and !== will call the equals() function in the
 Object base class.
Two questions: 1 - Waht about assignment? Object1 a; Object1 b; a = b; // by-reference assignment ???? // by-value assignment? 2 - What about integrating this syntax with pointers? Like this: int *p; int *q; ... ---- if (p === q) ... ---- is the same as : ---- if (*p == *q) ... ---- Ciao
Mar 27 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
news:a7rutn$1va1$1 digitaldaemon.com...
 1 - Waht about assignment?

     Object1 a;
     Object1 b;

     a = b;  // by-reference assignment
     ????    // by-value assignment?
I was thinking of a dup() method in Object.
 2 - What about integrating this syntax with pointers? Like this:
     int *p;
     int *q;
     ...
     ----
     if (p === q)
       ...
     ----
        is the same as  :
     ----
     if (*p == *q)
Yes, that would be consistent.
Mar 27 2002
next sibling parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a7s4ag$223b$1 digitaldaemon.com...
 "Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
 news:a7rutn$1va1$1 digitaldaemon.com...
 1 - Waht about assignment?

     Object1 a;
     Object1 b;

     a = b;  // by-reference assignment
     ????    // by-value assignment?
I was thinking of a dup() method in Object.
The default version (straight copy all members) will be generated automatically?
Mar 27 2002
next sibling parent reply "Roberto Mariottini" <rmariottini lycosmail.com> writes:
"Pavel Minayev" <evilone omen.ru> ha scritto nel messaggio
news:a7sdik$270c$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:a7s4ag$223b$1 digitaldaemon.com...
 "Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
 news:a7rutn$1va1$1 digitaldaemon.com...
 1 - Waht about assignment?

     Object1 a;
     Object1 b;

     a = b;  // by-reference assignment
     ????    // by-value assignment?
I was thinking of a dup() method in Object.
The default version (straight copy all members) will be generated automatically?
The default version should call dup() on every object-type member instead of doing a memcpy. Ciao
Mar 27 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
"Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
news:a7sfup$285c$1 digitaldaemon.com...

 The default version should call dup() on every object-type member
 instead of doing a memcpy.
In fact, most languages have two versions - one that simply copies object bit-by-bit, another which does the deep copy.
Mar 27 2002
prev sibling parent "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a7sdik$270c$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:a7s4ag$223b$1 digitaldaemon.com...
 "Roberto Mariottini" <rmariottini lycosmail.com> wrote in message
 news:a7rutn$1va1$1 digitaldaemon.com...
 1 - Waht about assignment?

     Object1 a;
     Object1 b;

     a = b;  // by-reference assignment
     ????    // by-value assignment?
I was thinking of a dup() method in Object.
The default version (straight copy all members) will be generated automatically?
Yes.
Apr 12 2002
prev sibling parent reply "Immanuel Scholz" <digital-mars kutzsche.net> writes:
 1 - Waht about assignment?

     Object1 a;
     Object1 b;

     a = b;  // by-reference assignment
     ????    // by-value assignment?
I was thinking of a dup() method in Object.
name it clone() dup is somewhat.....somewhat..... clone() is better, I think ;-) Imi
Mar 27 2002
next sibling parent "Sean L. Palmer" <spalmer iname.com> writes:
Yeah, dup is so FORTH.  ;)

Sean

"Immanuel Scholz" <digital-mars kutzsche.net> wrote in message
news:a7t3cs$2it9$1 digitaldaemon.com...

 I was thinking of a dup() method in Object.
name it clone() dup is somewhat.....somewhat..... clone() is better, I think ;-) Imi
Mar 27 2002
prev sibling parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Immanuel Scholz" <digital-mars kutzsche.net> wrote in message
news:a7t3cs$2it9$1 digitaldaemon.com...

 clone() is better, I think ;-)
And it is a standard de facto.
Mar 27 2002
next sibling parent "OddesE" <OddesE_XYZ hotmail.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a7tdm2$2o86$1 digitaldaemon.com...
 "Immanuel Scholz" <digital-mars kutzsche.net> wrote in message
 news:a7t3cs$2it9$1 digitaldaemon.com...

 clone() is better, I think ;-)
And it is a standard de facto.
Agreed. -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
Mar 27 2002
prev sibling parent DrWhat? <blackmarlin nospam.asean-mail.com> writes:
Pavel Minayev wrote:

 "Immanuel Scholz" <digital-mars kutzsche.net> wrote in message
 news:a7t3cs$2it9$1 digitaldaemon.com...
 
 clone() is better, I think ;-)
And it is a standard de facto.
And more fun ... Sheep aSheep = new Sheep(); Sheep dolly = aSheep.clone(); :-) C 2002/3/28
Mar 28 2002
prev sibling next sibling parent reply Juarez Rudsatz <juarez correio.com> writes:
"Walter" <walter digitalmars.com> wrote in
news:a7r7ok$1ing$2 digitaldaemon.com: 

 I've been reading all the messages on string comparisons, and propose
 the following:
 
 Since <, <=, >, >= make little sense on dynamic array references,
 those are by value. Introduce two new operators, === and !==, to do a
 by-value comparison for arrays. Similarly, for class objects, == and
 != will compare the references, and === and !== will call the equals()
 function in the Object base class.
 
 
How about the Barry solution :

I'm curious now ... what about array slicing threw a wrench in the works? if (a[] == b) if (a[w..x] == b) if (a[] == b[y..z]) if (a[w..x] == b[y..z]) seem ok to me at first glance (of somebody not actually implementing the dang thing), unless you really wanted to compare-by-reference and not by- contents, in the 2nd and 4th cases. Barry
Mar 27 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Juarez Rudsatz" <juarez correio.com> wrote in message
news:Xns91DE7FB166B28juarezcom 63.105.9.61...
 I'm curious now ... what about array slicing threw a wrench in the works?
a a[] a[0..a.length] all semantically mean the same thing as rvalues. Hence, no way to distinguish. As lvalues, I *can* distinguish them.
Mar 27 2002
parent reply Barry Pederson <barryp yahoo.com> writes:
Walter wrote:
 "Juarez Rudsatz" <juarez correio.com> wrote in message
 news:Xns91DE7FB166B28juarezcom 63.105.9.61...
 
I'm curious now ... what about array slicing threw a wrench in the works?
a a[] a[0..a.length] all semantically mean the same thing as rvalues. Hence, no way to distinguish. As lvalues, I *can* distinguish them.
If I understand correctly, you mean the compiler would treat all these the same way: if (b[] == a) if (b[] == a[]) if (b[] == a[0..a.length]) which sounds good to me. As a D end-user, that's what I would have expected I guess. So I'm still scratching my head over this, and curious as to why it's a problem. Not so much to press the point of advocating that particular syntax, but mainly because it's kind if enlightening to be observing the beginning of a new language and pick up little tidbits here and there from Walter as to why things are or aren't workable for a compiler. Barry
Mar 28 2002
parent "Walter" <walter digitalmars.com> writes:
"Barry Pederson" <barryp yahoo.com> wrote in message
news:3CA35185.1070805 yahoo.com...
 If I understand correctly, you mean the compiler would treat all these the
 same way:
    if (b[] == a)
    if (b[] == a[])
    if (b[] == a[0..a.length])
Yes.
 So I'm still scratching my head over this, and curious as to why it's a
 problem.  Not so much to press the point of advocating that particular
 syntax, but mainly because it's kind if enlightening to be observing the
 beginning of a new language and pick up little tidbits here and there from
 Walter as to why things are or aren't workable for a compiler.
The problem is how do you say you want to compare the contents of the array instead of the reference to the array?
Apr 13 2002
prev sibling next sibling parent Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Walter wrote:

 I've been reading all the messages on string comparisons, and propose the
 following:

 Since <, <=, >, >= make little sense on dynamic array references, those are
 by value. Introduce two new operators, === and !==, to do a by-value
 comparison for arrays. Similarly, for class objects, == and != will compare
 the references, and === and !== will call the equals() function in the
 Object base class.
What about multidimensional arrays? When you use the === operator, are you comparing the second, third, (and so on) dimensions by value or by reference? I'm still kind of partial to the (a[] == b[]) syntax, particularly if the number of []'s represents the depth of compare-by-value (any deeper and it's compare by reference). -- 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))) ]
Mar 27 2002
prev sibling next sibling parent reply "Richard Krehbiel" <rich kastle.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a7r7ok$1ing$2 digitaldaemon.com...
 I've been reading all the messages on string comparisons, and propose the
 following:

 Since <, <=, >, >= make little sense on dynamic array references, those
are
 by value. Introduce two new operators, === and !==, to do a by-value
 comparison for arrays. Similarly, for class objects, == and != will
compare
 the references, and === and !== will call the equals() function in the
 Object base class.
IMHO: For dynamic arrays, a = b should make b be a reference to a, a[] = b[] should copy the values from b to a, and == and != should do value comparisons. Similarly, for objects, a = b should make a reference, a = b.clone() wil ask b to make a copy of itself, and == and != should call .equals(). (IOW I think Java does this okay.) Comparing references is so frequently a mistake, that I'm inclined to want it to be difficult. If you simply must know, maybe do it by casting the object or array to void* (that .pointer property was also a good idea) and compare those. Dealing with = vs == is enough, thank you. Please don't add any such operators as === and !==. -- Richard Krehbiel, Arlington, VA, USA rich kastle.com (work) or krehbiel3 comcast.net (personal)
Mar 27 2002
next sibling parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Richard Krehbiel" <rich kastle.com> wrote in message
news:a7t1n7$2i4a$1 digitaldaemon.com...

 Comparing references is so frequently a mistake, that I'm inclined to want
 it to be difficult.  If you simply must know, maybe do it by casting the
 object or array to void* (that .pointer property was also a good idea) and
 compare those.
Comparing references is, in fact, more frequent than comparing values, for objects.
 Dealing with = vs == is enough, thank you.  Please don't add any such
 operators as === and !==.
They are already in JavaScript, and I'd say they work rather good. I haven't _ever_ confused == with ===.
Mar 27 2002
next sibling parent reply "Sean L. Palmer" <spalmer iname.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a7tdul$2oan$1 digitaldaemon.com...

 I haven't _ever_ confused == with ===.
Good for you. That will help all the people who do confuse them.
Mar 28 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
"Sean L. Palmer" <spalmer iname.com> wrote in message
news:a7unkc$bpm$1 digitaldaemon.com...

 Good for you.  That will help all the people who do confuse them.
And who does? I've never seen === in any language other than JavaScript, and I've never heard of any JS programmer who confuses == with ===.
Mar 28 2002
prev sibling parent reply "Rchard Krehbiel" <krehbiel3 comcast.net> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a7tdul$2oan$1 digitaldaemon.com...
 "Richard Krehbiel" <rich kastle.com> wrote in message
 news:a7t1n7$2i4a$1 digitaldaemon.com...

 Comparing references is so frequently a mistake, that I'm inclined to
want
 it to be difficult.  If you simply must know, maybe do it by casting the
 object or array to void* (that .pointer property was also a good idea)
and
 compare those.
Comparing references is, in fact, more frequent than comparing values, for objects.
I don't think this is correct. The only time I can imagine caring if Object a refers to the same thing as Object b is when I'm writing the "element delete" function for a singly-linked list. And with with decent collection class libraries, I shouldn't be needing to do that.
Mar 28 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Rchard Krehbiel" <krehbiel3 comcast.net> wrote in message
news:a802rh$13io$1 digitaldaemon.com...
 "Pavel Minayev" <evilone omen.ru> wrote in message
 news:a7tdul$2oan$1 digitaldaemon.com...
 Comparing references is, in fact, more frequent than comparing values,
 for objects.
I don't think this is correct. The only time I can imagine caring if Object a refers to the same thing as Object b is when I'm writing the "element delete" function for a singly-linked list. And with with decent collection class libraries, I shouldn't be needing to do that.
I use it often when, for example, doing a reverse lookup on an array. I use it in the thread package to determine if the 'this' refers to the currently executing thread or not.
Apr 16 2002
parent reply "Richard Krehbiel" <rich kastle.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a9hp9p$12cf$1 digitaldaemon.com...
 "Rchard Krehbiel" <krehbiel3 comcast.net> wrote in message
 news:a802rh$13io$1 digitaldaemon.com...
 "Pavel Minayev" <evilone omen.ru> wrote in message
 news:a7tdul$2oan$1 digitaldaemon.com...
 Comparing references is, in fact, more frequent than comparing values,
 for objects.
I don't think this is correct. The only time I can imagine caring if Object a refers to the same thing
as
 Object b is when I'm writing the "element delete" function for a
 singly-linked list. And with with decent collection class libraries, I
 shouldn't be needing to do that.
I use it often when, for example, doing a reverse lookup on an array. I
use
 it in the thread package to determine if the 'this' refers to the
currently
 executing thread or not.
But, do you compare references *more* *often* than you compare content? How often would a reference comparison be a mistake rather than the intent? I think content comparison is much more likely to be a programmer's intent, so when he codes "if(objA == objB)", do a content comparison. When he intends reference comparison, he can code "if(&objA == &objB)". -- Richard Krehbiel, Arlington, VA, USA rich kastle.com (work) or krehbiel3 comcast.net (personal)
Apr 16 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Richard Krehbiel" <rich kastle.com> wrote in message
news:a9hq7r$1385$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 But, do you compare references *more* *often* than you compare content?
How
 often would a reference comparison be a mistake rather than the intent?
Hard to say. With string arrays, I compare content. With objects, I compare references.
 I think content comparison is much more likely to be a programmer's
intent,
 so when he codes "if(objA == objB)", do a content comparison.  When he
 intends reference comparison, he can code "if(&objA == &objB)".
&x means the address of the reference. I don't think that will semantically work. Hmm, maybe "if (a [==] b)" ?? I have to think about this some more.
Apr 16 2002
next sibling parent reply Russell Borogove <kaleja estarcion.com> writes:
Walter wrote:

 
so when he codes "if(objA == objB)", do a content comparison.  When he
intends reference comparison, he can code "if(&objA == &objB)".
&x means the address of the reference. I don't think that will semantically work. Hmm, maybe "if (a [==] b)" ?? I have to think about this some more.
Ewwwww.
Apr 16 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Russell Borogove" <kaleja estarcion.com> wrote in message
news:3CBCCA22.9030407 estarcion.com...
 Walter wrote:
 Hmm, maybe "if (a [==] b)" ?? I have to think about this some more.
Ewwwww.
<cough cough> I guess that settles it <g>
Apr 16 2002
parent reply "Robert W. Cunningham" <rcunning acm.org> writes:
Walter wrote:

 "Russell Borogove" <kaleja estarcion.com> wrote in message
 news:3CBCCA22.9030407 estarcion.com...
 Walter wrote:
 Hmm, maybe "if (a [==] b)" ?? I have to think about this some more.
Ewwwww.
<cough cough> I guess that settles it <g>
Well, how about: "if (a is b)"? Yes, YAKW (Yet Another KeyWord). But it does flow, doesn't it? We could always FORTRAN-ize it: "if (a .IS. b)" How about a trigraph? -BobC
Apr 16 2002
parent Roberto Mariottini <rmariottini lycosmail.com> writes:
In article <3CBCEF97.FCCDA985 acm.org>, Robert W. Cunningham says...
Walter wrote:

 "Russell Borogove" <kaleja estarcion.com> wrote in message
 news:3CBCCA22.9030407 estarcion.com...
 Walter wrote:
 Hmm, maybe "if (a [==] b)" ?? I have to think about this some more.
Ewwwww.
<cough cough> I guess that settles it <g>
Well, how about: "if (a is b)"? Yes, YAKW (Yet Another KeyWord). But it does flow, doesn't it? We could always FORTRAN-ize it: "if (a .IS. b)" How about a trigraph?
How about a GIF of a cat that eats a mouse? :-) Ciao
Apr 17 2002
prev sibling next sibling parent reply Karl Bochert <kbochert ix.netcom.com> writes:
On Tue, 16 Apr 2002 12:21:21 -0700, "Walter" <walter digitalmars.com> wrote:
 
 &x means the address of the reference. I don't think that will semantically
 work.
 
 Hmm, maybe "if (a [==] b)" ?? I have to think about this some more.
 
if ( a := b ) if ( a === b ) // my favorite -- they are really, really the same if ( a <eq> b ) if ( identical ( a, b ) ) Karl Bochert
Apr 16 2002
parent "Stephen Fuld" <s.fuld.pleaseremove att.net> writes:
"Karl Bochert" <kbochert ix.netcom.com> wrote in message
news:1103_1019015587 bose...
 On Tue, 16 Apr 2002 12:21:21 -0700, "Walter" <walter digitalmars.com>
wrote:
 &x means the address of the reference. I don't think that will
semantically
 work.

 Hmm, maybe "if (a [==] b)" ?? I have to think about this some more.
if ( a := b ) if ( a === b ) // my favorite -- they are really, really the same if ( a <eq> b ) if ( identical ( a, b ) )
As someone posted before, why not use the notion of properties of an object with the dot notation? This meakes things really clear, i.e. prevents confusion. For example if (a.id == b.id) // where id is a property of the object - its unique identity, probably its address. or converesly if (a.content == b.content) // clearly not the address comprisons Chose whatever key words you want, etc. but why do we need confusing special character sequences when short words convey what is going on so much better and thus avoid confusion? Surely we are past the days when C was designed to minimize keystrokes because they were done on a KSR 33 teletype at 110 baud. -- - Stephen Fuld e-mail address disguised to prevent spam
Apr 17 2002
prev sibling next sibling parent "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a9i80p$1v5a$1 digitaldaemon.com...

 &x means the address of the reference. I don't think that will
semantically
 work.
Yep, right.
 Hmm, maybe "if (a [==] b)" ?? I have to think about this some more.
I remember you proposed === for arrays, maybe the same for objects?
Apr 16 2002
prev sibling parent reply "Sean L. Palmer" <spalmer iname.com> writes:
I don't see what the problem is.  The reference should be a basically hidden
thing anyway, acting for all intents and purpose like it actually *is* the
object it refers to.  You've seen references in C++... the following C++
code is completely legal (and I use stuff like this on a regular basis):

class Foo
{
};

Foo a;
Foo& aref = a;
Foo* arefptr = &aref;
assert(arefptr == &a);

Sean

"Walter" <walter digitalmars.com> wrote in message
news:a9i80p$1v5a$1 digitaldaemon.com...
 "Richard Krehbiel" <rich kastle.com> wrote in message
 news:a9hq7r$1385$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 But, do you compare references *more* *often* than you compare content?
How
 often would a reference comparison be a mistake rather than the intent?
Hard to say. With string arrays, I compare content. With objects, I
compare
 references.

 I think content comparison is much more likely to be a programmer's
intent,
 so when he codes "if(objA == objB)", do a content comparison.  When he
 intends reference comparison, he can code "if(&objA == &objB)".
&x means the address of the reference. I don't think that will
semantically
 work.

 Hmm, maybe "if (a [==] b)" ?? I have to think about this some more.
Apr 17 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
"Sean L. Palmer" <spalmer iname.com> wrote in message
news:a9jh6h$2vb3$1 digitaldaemon.com...

 I don't see what the problem is.  The reference should be a basically
hidden
 thing anyway, acting for all intents and purpose like it actually *is* the
 object it refers to.  You've seen references in C++... the following C++
This understanding of reference I've only seen in C++ so far. Ask any Delphi, or VB, or Java programmer, they tell you that reference is practically just a pointer that doesn't support pointer arithmetic. This comes from the fact that C++ references are constant, while in D they change.
Apr 17 2002
prev sibling parent reply "OddesE" <OddesE_XYZ hotmail.com> writes:
"Richard Krehbiel" <rich kastle.com> wrote in message
news:a7t1n7$2i4a$1 digitaldaemon.com...
<SNIP>
 Dealing with = vs == is enough, thank you.  Please don't add any such
 operators as === and !==.

 --
 Richard Krehbiel, Arlington, VA, USA
 rich kastle.com (work) or krehbiel3 comcast.net  (personal)
The reason == and = are often mistaken (IMHO) is that for lots of people = means equals. Certainly it usually means that in math... :) Assignment in math is not a standard operation, they use let? (let a = 10)... Also Pascal uses := for assignment and = for comparison. === on the other hand is not a standard symbol in math and people already (must) know that there is a difference between = and ==, so learning === should be easy. -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
Mar 27 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
"OddesE" <OddesE_XYZ hotmail.com> wrote in message
news:a7tl44$2s36$1 digitaldaemon.com...

 Assignment in math is not a standard operation,
 they use let? (let a = 10)...
 Also Pascal uses := for assignment and = for
 comparison.
Hm, I've always thought that := is a standard math assignment? At least MathCAD uses it for that purpose...
 === on the other hand is not a standard symbol
 in math and people already (must) know that there
 is a difference between = and ==, so learning
 === should be easy.
Yes, right.
Mar 27 2002
prev sibling next sibling parent reply "Stephen Fuld" <s.fuld.pleaseremove att.net> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a7r7ok$1ing$2 digitaldaemon.com...
 I've been reading all the messages on string comparisons, and propose the
 following:

 Since <, <=, >, >= make little sense on dynamic array references, those
are
 by value. Introduce two new operators, === and !==, to do a by-value
 comparison for arrays. Similarly, for class objects, == and != will
compare
 the references, and === and !== will call the equals() function in the
 Object base class.
Does this imply that equality comparisons will be supported on the contents of "strings", but not greater than or less than? That seems like a bad idea, as such comparisons are often quite usefull. -- - Stephen Fuld e-mail address disguised to prevent spam
Mar 27 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Stephen Fuld" <s.fuld.pleaseremove att.net> wrote in message
news:a7t4ch$2jfd$3 digitaldaemon.com...

 Does this imply that equality comparisons will be supported on the
contents
 of "strings", but not greater than or less than?  That seems like a bad
 idea, as such comparisons are often quite usefull.
From the very first post in the thread: "Since <, <=, >, >= make little sense on dynamic array references, those are by value." So you will be able to perform comparisons on strings and other arrays.
Mar 27 2002
parent "Stephen Fuld" <s.fuld.pleaseremove att.net> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a7tdof$2o8r$1 digitaldaemon.com...
 "Stephen Fuld" <s.fuld.pleaseremove att.net> wrote in message
 news:a7t4ch$2jfd$3 digitaldaemon.com...

 Does this imply that equality comparisons will be supported on the
contents
 of "strings", but not greater than or less than?  That seems like a bad
 idea, as such comparisons are often quite usefull.
From the very first post in the thread: "Since <, <=, >, >= make little sense on dynamic array references, those
are
 by value."

 So you will be able to perform comparisons on strings and other arrays.
Thanks. I guess I had a brain glitch. :-( -- - Stephen Fuld e-mail address disguised to prevent spam
Mar 27 2002
prev sibling parent reply "OddesE" <OddesE_XYZ hotmail.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a7r7ok$1ing$2 digitaldaemon.com...
 I've been reading all the messages on string comparisons, and propose the
 following:

 Since <, <=, >, >= make little sense on dynamic array references, those
are
 by value. Introduce two new operators, === and !==, to do a by-value
 comparison for arrays. Similarly, for class objects, == and != will
compare
 the references, and === and !== will call the equals() function in the
 Object base class.
I love it! I would like it vice versa, so == is by value in all situations (base type, array, object, struct), and === by reference, but that's nitpicking and it would break a lot of existing code. I read your posts on dup() and equals(). Basically you are doing a lot of what I was hoping for with my request for standard interfaces for operators in the thread "Operator overloading, a way to make everybody happy?", but instead of using interfaces, you are placing the functions directly in Object. It doesn't really matter, it's the end result that counts! This way is probably a lot more efficient? Let me get it straight: MyObject a = new MyObject, b = new MyObject; ... if (a === b) // will translate to if (a.equals (b)) ? if (a !== b) // will translate to if (! a.equals (b)) ? if (a > b) // will translate to if (a.cmp (b) > 0) ? if (a >= b) // will translate to if (a.cmp (b) >= 0) ? if (a < b) // will translate to if (a.cmp (b) < 0) ? if (a <= b) // will translate to if (a.cmp (b) <= 0) ? a = b // will translate to a.dup (b) ? If this is true, I'm sold! I would love that! Now building on this you might implement addition, subtraction, multiplication and division in much the same way. The default implementation of add() etc in object would just throw an OperatorNotSupported exception, but descendant classes could override them to do some serious work! Ofcourse, functionality to check what operators a class supports would also be very welcome: if (a.supportsop (Operator.PLUS)) // .... Sorry for grabbing the hand as soon as you give me a finger, but I love the concept of operator overloading, and this would make it fairly transparent to implement. Also, operator overloading haters could always directly call the normal functions. Thanks Walter, great! -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net __________________________________________ Remove _XYZ from my address when replying by mail
Mar 27 2002
parent reply "Walter" <walter digitalmars.com> writes:
"OddesE" <OddesE_XYZ hotmail.com> wrote in message
news:a7tk0m$2rgu$1 digitaldaemon.com...
 Sorry for grabbing the hand as soon as you give me a
 finger, but I love the concept of operator overloading,
 and this would make it fairly transparent to implement.
 Also, operator overloading haters could always directly
 call the normal functions.
It does seem like I've fallen backwards into supporting operator overloading <g>.
Apr 17 2002
parent reply "OddesE" <OddesE_XYZ hotmail.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a9j73p$2mhs$1 digitaldaemon.com...
 "OddesE" <OddesE_XYZ hotmail.com> wrote in message
 news:a7tk0m$2rgu$1 digitaldaemon.com...
 Sorry for grabbing the hand as soon as you give me a
 finger, but I love the concept of operator overloading,
 and this would make it fairly transparent to implement.
 Also, operator overloading haters could always directly
 call the normal functions.
It does seem like I've fallen backwards into supporting operator
overloading
 <g>.
I'd rather call it jumping forwards ;) But what about it? Any plans on add, subtract, divide and multiply? (Sorry, gotta ask :) ) -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
Apr 18 2002
parent "Walter" <walter digitalmars.com> writes:
"OddesE" <OddesE_XYZ hotmail.com> wrote in message
news:a9n0gm$2vvl$1 digitaldaemon.com...
 It does seem like I've fallen backwards into supporting operator
overloading
 <g>.
I'd rather call it jumping forwards ;) But what about it? Any plans on add, subtract, divide and multiply? (Sorry, gotta ask :) )
Right now I want to finish what I've got, and ship it. There's always 2.0!
Apr 18 2002