Re: T[new] misgivings

2009-10-20 Thread Steven Schveighoffer
On Fri, 16 Oct 2009 05:49:12 -0400, Walter Bright newshou...@digitalmars.com wrote: Don wrote: There are two sensible options: I see the question as, is T[new] a value type or a reference type? I see it as a reference type, and so assignment should act like a reference assignment, not

Re: T[new] misgivings

2009-10-20 Thread Andrei Alexandrescu
Steven Schveighoffer wrote: On Fri, 16 Oct 2009 05:49:12 -0400, Walter Bright newshou...@digitalmars.com wrote: Don wrote: There are two sensible options: I see the question as, is T[new] a value type or a reference type? I see it as a reference type, and so assignment should act like a

Re: T[new] misgivings

2009-10-19 Thread Kagamin
Andrei Alexandrescu Wrote: Paradoxically this seems to be conducive to subtle efficiency issues. For example, consider: int[new] a; ... a = [1, 2, 3]; What should that do? a = new Appender!int([1,2,3]); What you describe is more like StringBuilder, and, yes, things like that require

Re: T[new] misgivings

2009-10-17 Thread Sergey Gromov
Thu, 15 Oct 2009 21:55:07 -0500, Andrei Alexandrescu wrote: int[new] a; ... a = [1, 2, 3]; What should that do? To me a is an array, a reference type. Therefore assignment here means rebinding a to a new array created from a literal. A: Ok, then how do I say the common operation I want

Re: T[new] misgivings

2009-10-17 Thread Sergey Gromov
Thu, 15 Oct 2009 23:18:22 -0500, Andrei Alexandrescu wrote: Jeremie Pelletier wrote: Andrei Alexandrescu wrote: Jeremie Pelletier wrote: Andrei Alexandrescu wrote: Walter Bright wrote: Andrei Alexandrescu wrote: This goes into something more interesting that I thought of after the

Re: T[new] misgivings

2009-10-16 Thread Lutger
Just to understand it: int[new] a; int[new] b; a = [1,2,3]; b = a; In your book, the last statement would copy contents of a into b and b.ptr != a.ptr while according to walter, b would rebind to a?

Re: T[new] misgivings

2009-10-16 Thread Don
Andrei Alexandrescu wrote: I talked to Walter about T[new] today and it seems we are having a disagreement. The problem is that I believe T[new] is a container, whereas Walter believes T[new] is nothing but a slice with a couple of extra operations. Paradoxically this seems to be conducive

Re: T[new] misgivings

2009-10-16 Thread Don
Max Samukha wrote: On Thu, 15 Oct 2009 21:55:07 -0500, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: I talked to Walter about T[new] today and it seems we are having a disagreement. I'd prefer Walter's way with a provision that array literals are immutable and allocated

Re: T[new] misgivings

2009-10-16 Thread Walter Bright
Don wrote: There are two sensible options: I see the question as, is T[new] a value type or a reference type? I see it as a reference type, and so assignment should act like a reference assignment, not a value assignment.

Re: T[new] misgivings

2009-10-16 Thread Walter Bright
Don wrote: Max Samukha wrote: // arrays are true reference types int[new] a = [1, 2, 3]; b = a; a.length = 22; assert (a.length == b.length); This makes perfect sense to me. The rule would be: If 'x' is T[new], then: x = y; _always_ copies y into a {length, capacity-specified block}, unless

Re: T[new] misgivings

2009-10-16 Thread Max Samukha
On Fri, 16 Oct 2009 02:53:20 -0700, Walter Bright newshou...@digitalmars.com wrote: Don wrote: Max Samukha wrote: // arrays are true reference types int[new] a = [1, 2, 3]; b = a; a.length = 22; assert (a.length == b.length); This makes perfect sense to me. The rule would be: If 'x' is

Re: T[new] misgivings

2009-10-16 Thread Fawzi Mohamed
On 2009-10-16 11:49:12 +0200, Walter Bright newshou...@digitalmars.com said: Don wrote: There are two sensible options: I see the question as, is T[new] a value type or a reference type? I see it as a reference type, and so assignment should act like a reference assignment, not a value

Re: T[new] misgivings

2009-10-16 Thread Fawzi Mohamed
On 2009-10-16 13:54:03 +0200, Max Samukha spam...@d-coding.com said: On Fri, 16 Oct 2009 02:53:20 -0700, Walter Bright newshou...@digitalmars.com wrote: Don wrote: Max Samukha wrote: // arrays are true reference types int[new] a = [1, 2, 3]; b = a; a.length = 22; assert (a.length ==

Re: T[new] misgivings

2009-10-16 Thread Don
Fawzi Mohamed wrote: On 2009-10-16 13:54:03 +0200, Max Samukha spam...@d-coding.com said: On Fri, 16 Oct 2009 02:53:20 -0700, Walter Bright newshou...@digitalmars.com wrote: Don wrote: Max Samukha wrote: // arrays are true reference types int[new] a = [1, 2, 3]; b = a; a.length = 22;

Re: T[new] misgivings

2009-10-16 Thread Max Samukha
On Fri, 16 Oct 2009 14:25:44 +0200, Don nos...@nospam.com wrote: Yes, but you could allocate the data immediately after the Array structure, so you only have one allocation. And in the common case, where it never exceeds the original capacity, they stay together and preserve cache locality.

Re: T[new] misgivings

2009-10-16 Thread Andrei Alexandrescu
Don wrote: Max Samukha wrote: On Thu, 15 Oct 2009 21:55:07 -0500, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: I talked to Walter about T[new] today and it seems we are having a disagreement. I'd prefer Walter's way with a provision that array literals are immutable and

Re: T[new] misgivings

2009-10-16 Thread Andrei Alexandrescu
Walter Bright wrote: Don wrote: There are two sensible options: I see the question as, is T[new] a value type or a reference type? I see it as a reference type, and so assignment should act like a reference assignment, not a value assignment. I understand that, but to me that's an example

Re: T[new] misgivings

2009-10-16 Thread Andrei Alexandrescu
Walter Bright wrote: I think it would be very strange to have T[] behave like a reference type (which it does now) and T[new] to behave like a value type. T[] is not a reference type. Andrei

Re: T[new] misgivings

2009-10-16 Thread Andrei Alexandrescu
Max Samukha wrote: On Fri, 16 Oct 2009 14:25:44 +0200, Don nos...@nospam.com wrote: Yes, but you could allocate the data immediately after the Array structure, so you only have one allocation. And in the common case, where it never exceeds the original capacity, they stay together and

Re: T[new] misgivings

2009-10-16 Thread Don
Don wrote: Andrei Alexandrescu wrote: Don wrote: Max Samukha wrote: On Thu, 15 Oct 2009 21:55:07 -0500, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: I talked to Walter about T[new] today and it seems we are having a disagreement. I'd prefer Walter's way with a provision that

Re: T[new] misgivings

2009-10-16 Thread Andrei Alexandrescu
Don wrote: In case this isn't clear: real [] sinsTable = [ sin(1.0), sin(2.0), sin(3.0), sin(4.0) ]; How do you do this so that the entries in the table are calculated at compile time? static? Andrei

Re: T[new] misgivings

2009-10-16 Thread Andrei Alexandrescu
Lutger wrote: Just to understand it: int[new] a; int[new] b; a = [1,2,3]; b = a; In your book, the last statement would copy contents of a into b and b.ptr != a.ptr while according to walter, b would rebind to a? Well no. In the case above b would rebind to a, which is consistent with:

Re: T[new] misgivings

2009-10-16 Thread Don
Andrei Alexandrescu wrote: Don wrote: In case this isn't clear: real [] sinsTable = [ sin(1.0), sin(2.0), sin(3.0), sin(4.0) ]; How do you do this so that the entries in the table are calculated at compile time? static? Andrei That's still not compile time. They're initialized in the

Re: T[new] misgivings

2009-10-16 Thread Max Samukha
On Fri, 16 Oct 2009 09:00:27 -0500, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: Don wrote: Max Samukha wrote: On Thu, 15 Oct 2009 21:55:07 -0500, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: I talked to Walter about T[new] today and it seems we are having a

Re: T[new] misgivings

2009-10-16 Thread Denis Koroskin
On Fri, 16 Oct 2009 18:30:24 +0400, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: Lutger wrote: Just to understand it: int[new] a; int[new] b; a = [1,2,3]; b = a; In your book, the last statement would copy contents of a into b and b.ptr != a.ptr while according to walter, b

Re: T[new] misgivings

2009-10-16 Thread Leandro Lucarella
Andrei Alexandrescu, el 16 de octubre a las 09:12 me escribiste: Max Samukha wrote: On Fri, 16 Oct 2009 14:25:44 +0200, Don nos...@nospam.com wrote: Yes, but you could allocate the data immediately after the Array structure, so you only have one allocation. And in the common case, where it

Re: T[new] misgivings

2009-10-16 Thread Jason House
Andrei Alexandrescu Wrote: Walter Bright wrote: I think it would be very strange to have T[] behave like a reference type (which it does now) and T[new] to behave like a value type. T[] is not a reference type. Andrei While true, normal use will be the same as if it was a reference

T[new] misgivings

2009-10-15 Thread Andrei Alexandrescu
I talked to Walter about T[new] today and it seems we are having a disagreement. The problem is that I believe T[new] is a container, whereas Walter believes T[new] is nothing but a slice with a couple of extra operations. Paradoxically this seems to be conducive to subtle efficiency issues.

Re: T[new] misgivings

2009-10-15 Thread Rainer Deyke
Andrei Alexandrescu wrote: int[new] a; a = [1, 2, 3]; What should that do? This question can be rephrased as, should 'int[new]' be a reference type or a value type (or something else)? If 'int[new]' is a reference type, then it must rebind, because that's what assignment does for

Re: T[new] misgivings

2009-10-15 Thread Walter Bright
Andrei Alexandrescu wrote: This goes into something more interesting that I thought of after the conversation. Consider: T[new] a; T[] b; ... a = b; What should that do? Error. T[] cannot be implicitly converted to T[new]

Re: T[new] misgivings

2009-10-15 Thread Robert Jacques
On Thu, 15 Oct 2009 23:16:56 -0400, Walter Bright newshou...@digitalmars.com wrote: Andrei Alexandrescu wrote: This goes into something more interesting that I thought of after the conversation. Consider: T[new] a; T[] b; ... a = b; What should that do? Error. T[] cannot be implicitly

Re: T[new] misgivings

2009-10-15 Thread Andrei Alexandrescu
Walter Bright wrote: Andrei Alexandrescu wrote: This goes into something more interesting that I thought of after the conversation. Consider: T[new] a; T[] b; ... a = b; What should that do? Error. T[] cannot be implicitly converted to T[new] Then your argument building on similarity

Re: T[new] misgivings

2009-10-15 Thread Andrei Alexandrescu
Rainer Deyke wrote: Andrei Alexandrescu wrote: int[new] a; a = [1, 2, 3]; What should that do? This question can be rephrased as, should 'int[new]' be a reference type or a value type (or something else)? If 'int[new]' is a reference type, then it must rebind, because that's what

Re: T[new] misgivings

2009-10-15 Thread Robert Jacques
On Thu, 15 Oct 2009 22:55:07 -0400, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: I talked to Walter about T[new] today and it seems we are having a disagreement. The problem is that I believe T[new] is a container, whereas Walter believes T[new] is nothing but a slice with a

Re: T[new] misgivings

2009-10-15 Thread Jason House
Andrei Alexandrescu Wrote: I talked to Walter about T[new] today and it seems we are having a disagreement. The problem is that I believe T[new] is a container, whereas Walter believes T[new] is nothing but a slice with a couple of extra operations. Paradoxically this seems to be

Re: T[new] misgivings

2009-10-15 Thread Jeremie Pelletier
Andrei Alexandrescu wrote: I talked to Walter about T[new] today and it seems we are having a disagreement. The problem is that I believe T[new] is a container, whereas Walter believes T[new] is nothing but a slice with a couple of extra operations. I agree with the container model, it

Re: T[new] misgivings

2009-10-15 Thread Andrei Alexandrescu
Robert Jacques wrote: I like (and have used) the opSliceAssign syntax to represent by value/copy assignment as opposed to opAssign's by reference syntax. You could always define T[new] auto-resize in the case of a[] = b, but then you'd have to decide if that behavior should be extended to

Re: T[new] misgivings

2009-10-15 Thread Rainer Deyke
Andrei Alexandrescu wrote: Rainer Deyke wrote: To answer the rephrased question: 'int[new]' should be a value type. Well Walter and I agreed they should be pass-by-reference. That doesn't mean they must be references, and the fact that the simplest syntax has the worst efficiency reminds me

Re: T[new] misgivings

2009-10-15 Thread Rainer Deyke
Andrei Alexandrescu wrote: Then your argument building on similarity between the two is weakened. T[new] a; T[] b; a = [1, 2, 3]; b = [1, 2, 3]; Central to your argument was that the two must do the same thing. Since now literals are in a whole new league (they aren't slices

Re: T[new] misgivings

2009-10-15 Thread dsimcha
== Quote from Andrei Alexandrescu (seewebsiteforem...@erdani.org)'s article I talked to Walter about T[new] today and it seems we are having a disagreement. The problem is that I believe T[new] is a container, whereas Walter believes T[new] is nothing but a slice with a couple of extra

Re: T[new] misgivings

2009-10-15 Thread Andrei Alexandrescu
Rainer Deyke wrote: Andrei Alexandrescu wrote: Rainer Deyke wrote: To answer the rephrased question: 'int[new]' should be a value type. Well Walter and I agreed they should be pass-by-reference. That doesn't mean they must be references, and the fact that the simplest syntax has the worst

Re: T[new] misgivings

2009-10-15 Thread Andrei Alexandrescu
Rainer Deyke wrote: Andrei Alexandrescu wrote: Then your argument building on similarity between the two is weakened. T[new] a; T[] b; a = [1, 2, 3]; b = [1, 2, 3]; Central to your argument was that the two must do the same thing. Since now literals are in a whole new league (they aren't

Re: T[new] misgivings

2009-10-15 Thread Jeremie Pelletier
Andrei Alexandrescu wrote: Walter Bright wrote: Andrei Alexandrescu wrote: This goes into something more interesting that I thought of after the conversation. Consider: T[new] a; T[] b; ... a = b; What should that do? Error. T[] cannot be implicitly converted to T[new] Then your

Re: T[new] misgivings

2009-10-15 Thread Andrei Alexandrescu
Jeremie Pelletier wrote: Andrei Alexandrescu wrote: Walter Bright wrote: Andrei Alexandrescu wrote: This goes into something more interesting that I thought of after the conversation. Consider: T[new] a; T[] b; ... a = b; What should that do? Error. T[] cannot be implicitly converted to

Re: T[new] misgivings

2009-10-15 Thread Jeremie Pelletier
Andrei Alexandrescu wrote: Jeremie Pelletier wrote: Andrei Alexandrescu wrote: Walter Bright wrote: Andrei Alexandrescu wrote: This goes into something more interesting that I thought of after the conversation. Consider: T[new] a; T[] b; ... a = b; What should that do? Error. T[] cannot

Re: T[new] misgivings

2009-10-15 Thread Andrei Alexandrescu
Jeremie Pelletier wrote: Andrei Alexandrescu wrote: Jeremie Pelletier wrote: Andrei Alexandrescu wrote: Walter Bright wrote: Andrei Alexandrescu wrote: This goes into something more interesting that I thought of after the conversation. Consider: T[new] a; T[] b; ... a = b; What should