April 19, 2002 Re: Array == and < | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "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(). |
April 19, 2002 Re: Array == and < | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "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 > element, > > === 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 be > by > > value or reference? > > By reference. By value is too expensive. But arrays are copy-on-write, or am I wrong? |
April 19, 2002 Re: Array == and < | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "Pavel Minayev" <evilone@omen.ru> wrote in message news:a9o3vk$pqa$1@digitaldaemon.com... > "Walter" <walter@digitalmars.com> wrote in message > > > 2.) Has consensus been reached on whether object/array assignment will > be > > by > > > value or reference? > > By reference. By value is too expensive. > But arrays are copy-on-write, or am I wrong? a = b[]; // assign by reference a[] = b[]; // assign by copy a[3] = 4; // changes a[3] in place (no copy on write) |
April 19, 2002 Re: Array == and < | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "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. |
April 22, 2002 Re: Array == and < | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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 |
April 22, 2002 Re: Array == and < | ||||
---|---|---|---|---|
| ||||
Posted in reply to Roberto Mariottini | "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 > Is it possible to write simply: > a = b; // assign by reference Yes. |
Copyright © 1999-2021 by the D Language Foundation