March 27, 2002 Re: Array comparisons | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "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 ===. |
March 27, 2002 Re: Array comparisons | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "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? |
March 27, 2002 Re: Array comparisons | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "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 |
March 27, 2002 Re: Array comparisons | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "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 |
March 27, 2002 Re: Array comparisons | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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))) ] |
March 27, 2002 Re: Array comparisons | ||||
---|---|---|---|---|
| ||||
Posted in reply to Roberto Mariottini | "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. |
March 27, 2002 Re: Array comparisons | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "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) |
March 27, 2002 Re: Array comparisons | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "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 |
March 27, 2002 Re: Array comparisons | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter |
> > 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
|
March 27, 2002 Re: Array comparisons | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "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 |
Copyright © 1999-2021 by the D Language Foundation