T[new]

2009-08-09 Thread Walter Bright
D has a number of subtle problems (performance and semantic) that arise when arrays are resized. The solution is to separate resizeable array types from slices. Slices will retain the old: T[] slice; syntax. Resizeable arrays will be declared as: T[new] array; The new expression

Re: T[new]

2009-08-09 Thread Brad Roberts
Yay. What will happen with slices over a T[new] when the underlying T[new] must be moved due to resizing? The behavior needs to be at least well specified, if not well defined. Walter Bright wrote: > D has a number of subtle problems (performance and semantic) that arise > when arra

Re: T[new]

2009-08-09 Thread Walter Bright
Brad Roberts wrote: Yay. What will happen with slices over a T[new] when the underlying T[new] must be moved due to resizing? The behavior needs to be at least well specified, if not well defined. Great question! It's no different from what happens with any container when its con

Re: T[new]

2009-08-09 Thread grauzone
That's great. I think this would finally fix some of the more pressing issues of D. I have a question: will T[new] a; allocate something? Or will the allocation of the hidden library array object delayed until the length is set to non null? If the library array object is not allo

Re: T[new]

2009-08-09 Thread Walter Bright
By the way, T[new] is Andrei's idea, as well as it being his idea to make it a reference type.

Re: T[new]

2009-08-09 Thread Walter Bright
grauzone wrote: will T[new] a; allocate something? Nope. Or will the allocation of the hidden library array object delayed until the length is set to non null? Yes. If the library array object is not allocated, will a.ptr, a.capacity and a.length simply return null? Yes. Clearly

Re: T[new]

2009-08-09 Thread bearophile
declared as: > T[new] array; Such syntaxes have to be chosen wisely. I don't fully understand that syntax. And maybe I don't fully like it. I think the default (simpler) syntax has to be the most flexible and safer construct, that is resizable arrays. Slices can be seen as an

Re: T[new]

2009-08-09 Thread bearophile
Walter Bright: > Under the hood, a T[new] will be a single pointer to a library defined > type. This library defined type will likely contain three properties: I have another question: are there some performance penalities in using such arrays for normal random access operations

Re: T[new]

2009-08-09 Thread Brad Roberts
Walter Bright wrote: > Brad Roberts wrote: >> Yay. What will happen with slices over a T[new] when the underlying >> T[new] must >> be moved due to resizing? The behavior needs to be at least well >> specified, if >> not well defined. > > Great question! I

Re: T[new]

2009-08-09 Thread Andrei Alexandrescu
bearophile wrote: Walter Bright: Under the hood, a T[new] will be a single pointer to a library defined type. This library defined type will likely contain three properties: I have another question: are there some performance penalities in using such arrays for normal random access

Re: T[new]

2009-08-09 Thread Andrei Alexandrescu
Brad Roberts wrote: Walter Bright wrote: Brad Roberts wrote: Yay. What will happen with slices over a T[new] when the underlying T[new] must be moved due to resizing? The behavior needs to be at least well specified, if not well defined. Great question! It's no different from what ha

Re: T[new]

2009-08-09 Thread Andrei Alexandrescu
will be declared as: T[new] array; Such syntaxes have to be chosen wisely. I don't fully understand that syntax. And maybe I don't fully like it. Why am I not surprised :o). I think the default (simpler) syntax has to be the most flexible and safer construct, that is resiza

Re: T[new]

2009-08-09 Thread BCS
Reply to bearophile, Walter Bright: 2. make arrays implementable on .net I don't care of such thing. dotnet already has C# and C# is probably better than D, I beg to differ. D is much better than c# in many ways (D's abstraction tools are WAY better; C#'s end at reflection and generics, b

Re: T[new]

2009-08-09 Thread bearophile
as to be the default syntax to keep the compatibility with C :-) Walter Bright: > Yes. Clearly, those properties will have to be functions under the hood. > So T[new] operations will be a bit slower than for slices. For faster > indexing, you'd probably want to do: > auto slice =

Re: T[new]

2009-08-09 Thread grauzone
bearophile wrote: 2. make arrays implementable on .net I don't care of such thing. dotnet already has C# and C# is probably better than D, and it's similar anyway. So I don't think people will use D on dotnet. So even if creating a D for dotnet can be positive, I don't want D2 to change its

Re: T[new]

2009-08-09 Thread Walter Bright
bearophile wrote: 2. make arrays implementable on .net I don't care of such thing. dotnet already has C# and C# is probably better than D, and it's similar anyway. So I don't think people will use D on dotnet. So even if creating a D for dotnet can be positive, I don't want D2 to change its des

Re: T[new]

2009-08-09 Thread bearophile
grauzone: > I see two things a dotnet implementation of D could have over native D: > - better garbage collector (the D one barely does its job...) The dotnet GC is probably better than the current D GC, but I think it's designed for mostly movable objects. Currently most (or all) D objects are

Re: T[new]

2009-08-09 Thread Stewart Gordon
Walter Bright wrote: Under the hood, a T[new] will be a single pointer to a library defined type. This library defined type will likely contain three properties: size_t length; T* ptr; size_t capacity; The usual array operations will work on T[new] as well as T[]. Would new T

Re: T[new]

2009-08-09 Thread Walter Bright
Stewart Gordon wrote: Walter Bright wrote: Under the hood, a T[new] will be a single pointer to a library defined type. This library defined type will likely contain three properties: size_t length; T* ptr; size_t capacity; The usual array operations will work on T[new] as well

Re: T[new]

2009-08-09 Thread grauzone
Stewart Gordon wrote: Moreover, would whatever happens solve such const/invariant holes as bug 2093? Just what happens to the ~= operator anyway? Right now, it appends data inline. My vote would be to make "a~=b" do the same as "a=a~b" (with types "T[] a" a

Re: T[new]

2009-08-09 Thread Leandro Lucarella
t; syntax. Resizeable arrays will be declared as: > >T[new] array; > > The new expression: > >new T[10] > > will return a T[new]. > > T[new] will implicitly convert to T[], but not the other way. > > slice.length will become read-only. > >

Re: T[new]

2009-08-09 Thread Michel Fortin
declared as: T[new] array; The new expression: new T[10] will return a T[new]. I have nothing against the concept of container, but I dislike like the syntax. Is this really better than Array!T ? T[new] will implicitly convert to T[], but not the other way. slice.length will become

Re: T[new]

2009-08-09 Thread Walter Bright
Michel Fortin wrote: But I know, unique isn't easy to implement to fit all the use cases we'd like to solve. I'm just sharing a dream. We explored unique at length, and trying to make it work would render the rest of the language nearly unusably complex.

Re: T[new]

2009-08-09 Thread Michiel Helvensteijn
Walter Bright wrote: >> But I know, unique isn't easy to implement to fit all the use cases we'd >> like to solve. I'm just sharing a dream. > > We explored unique at length, and trying to make it work would render > the rest of the language nearly unusably complex. I've heard 'unique' mentioned

Re: T[new]

2009-08-09 Thread Robert Jacques
On Sun, 09 Aug 2009 14:21:31 -0700, Walter Bright wrote: bearophile wrote: 2. make arrays implementable on .net I don't care of such thing. dotnet already has C# and C# is probably better than D, and it's similar anyway. So I don't think people will use D on dotnet. So even if creating a D

Re: T[new]

2009-08-09 Thread Sergey Gromov
Mon, 10 Aug 2009 01:56:35 +0200, Michiel Helvensteijn wrote: > Walter Bright wrote: > >>> But I know, unique isn't easy to implement to fit all the use cases we'd >>> like to solve. I'm just sharing a dream. >> >> We explored unique at length, and trying to make it work would render >> the rest

Re: T[new]

2009-08-09 Thread Lionello Lunesu
"Andrei Alexandrescu" wrote in message news:h5ndt0$1bl...@digitalmars.com... bearophile wrote: Walter Bright: Under the hood, a T[new] will be a single pointer to a library defined type. This library defined type will likely contain three properties: I have another question:

Re: T[new]

2009-08-09 Thread dsimcha
== Quote from bearophile (bearophileh...@lycos.com)'s article > Walter Bright: > > Under the hood, a T[new] will be a single pointer to a library defined > > type. This library defined type will likely contain three properties: > I have another question: are there some pe

Re: T[new]

2009-08-09 Thread Andrei Alexandrescu
Lionello Lunesu wrote: "Andrei Alexandrescu" wrote in message news:h5ndt0$1bl...@digitalmars.com... bearophile wrote: Walter Bright: Under the hood, a T[new] will be a single pointer to a library defined type. This library defined type will likely contain three properties

Re: T[new]

2009-08-09 Thread Jeremie Pelletier
bearophile Wrote: > grauzone: > > > I see two things a dotnet implementation of D could have over native D: > > - better garbage collector (the D one barely does its job...) > > The dotnet GC is probably better than the current D GC, but I think it's > designed for mostly movable objects. Curre

Re: T[new]

2009-08-09 Thread Graham St Jack
This sounds excellent.

Re: T[new]

2009-08-10 Thread Kagamin
Walter Bright Wrote: > Resizeable arrays will be declared as: > > T[new] array; > > The new expression: > > new T[10] > > will return a T[new]. > > T[new] will implicitly convert to T[], but not the other way. > > slice.length will become read-

Re: T[new]

2009-08-10 Thread Walter Bright
Kagamin wrote: Of what type will strings be? immutable(char)[] Of what type will be the result of concatenation? T[new]

Re: T[new]

2009-08-10 Thread Lars T. Kyllingstad
Walter Bright wrote: Kagamin wrote: Of what type will strings be? immutable(char)[] I've always wondered: Why are strings of type immutable(char)[], and not immutable(char[])? I mean, there is no point in allowing resizing of strings, when assigning to the new elements is impossible. -

Re: T[new]

2009-08-10 Thread Walter Bright
Lars T. Kyllingstad wrote: I've always wondered: Why are strings of type immutable(char)[], and not immutable(char[])? So: string a = "hello"; a = "foo"; works.

Re: T[new]

2009-08-10 Thread Lars T. Kyllingstad
Walter Bright wrote: Lars T. Kyllingstad wrote: I've always wondered: Why are strings of type immutable(char)[], and not immutable(char[])? So: string a = "hello"; a = "foo"; works. Ah, of course. :) Thanks. -Lars

Re: T[new]

2009-08-10 Thread Sergey Gromov
t; syntax. Resizeable arrays will be declared as: > > T[new] array; Good news. I'm all for it. The T[new] syntax is a bit... weird... bit I'm OK with it as well. Thanks!

Re: T[new]

2009-08-10 Thread Andrei Alexandrescu
Walter Bright wrote: Kagamin wrote: Of what type will strings be? immutable(char)[] Of what type will be the result of concatenation? T[new] Hmmm, I see a problem. auto s1 = "Hello"; auto s2 = " world"; auto s = s1 ~ s2; Some might be surprised that the type of

Re: T[new]

2009-08-10 Thread Steven Schveighoffer
On Mon, 10 Aug 2009 10:11:52 -0400, Andrei Alexandrescu wrote: Walter Bright wrote: Kagamin wrote: Of what type will strings be? immutable(char)[] Of what type will be the result of concatenation? T[new] Hmmm, I see a problem. auto s1 = "Hello"; auto s2 = " worl

Re: T[new]

2009-08-10 Thread Steven Schveighoffer
will be declared as: T[new] array; The new expression: new T[10] will return a T[new]. T[new] will implicitly convert to T[], but not the other way. slice.length will become read-only. Under the hood, a T[new] will be a single pointer to a library defined type. This library defined

Re: T[new]

2009-08-10 Thread Jarrett Billingsley
ax. Resizeable arrays will be declared as: > >   T[new] array; > > The new expression: > >   new T[10] > > will return a T[new]. > > T[new] will implicitly convert to T[], but not the other way. > > slice.length will become read-only. > > Under the hood, a T[

Re: T[new]

2009-08-10 Thread Jeremie Pelletier
Lars T. Kyllingstad Wrote: > Walter Bright wrote: > > Lars T. Kyllingstad wrote: > >> I've always wondered: Why are strings of type immutable(char)[], and > >> not immutable(char[])? > > > > So: > > > >string a = "hello"; > >a = "foo"; > > > > works. > > > Ah, of course. :) Thanks. >

Re: T[new]

2009-08-10 Thread Leandro Lucarella
immutable(char)[] was that any string can be resized, even > slices. > > Walter: what will the string types be aliased to now: still immutable(char)[] > or immutable(char)[new]? From: Walter Bright Date: Mon, 10 Aug 2009 01:01:56 -0700 Subject: Re: T[new] User-Agent: Thunderbird 2

Re: T[new]

2009-08-10 Thread Stewart Gordon
Since nobody's yet asked What type would .dup and .idup return? The best choice I can see is to make .dup return T[new] and .idup return invariant(T)[]. Stewart.

Re: T[new]

2009-08-10 Thread Stewart Gordon
Jeremie Pelletier wrote: Walter: what will the string types be aliased to now: still immutable(char)[] or immutable(char)[new]? I think it would be best to have them use the array [new] type. It would be more efficient to cut out this middleman for things that aren't going to change the len

Re: T[new]

2009-08-10 Thread Steven Schveighoffer
On Mon, 10 Aug 2009 14:38:24 -0400, Stewart Gordon wrote: Since nobody's yet asked What type would .dup and .idup return? The best choice I can see is to make .dup return T[new] and .idup return invariant(T)[]. This brings up another question. Should something like immuta

Re: T[new]

2009-08-10 Thread Andrei Alexandrescu
Steven Schveighoffer wrote: On Mon, 10 Aug 2009 14:38:24 -0400, Stewart Gordon wrote: Since nobody's yet asked What type would .dup and .idup return? The best choice I can see is to make .dup return T[new] and .idup return invariant(T)[]. This brings up another question. S

Re: T[new]

2009-08-10 Thread div0
-) > >> Slices will retain the old: >> T[] slice; >> syntax. Resizeable arrays will be declared as: >> T[new] array; > > Such syntaxes have to be chosen wisely. I don't fully understand that syntax. > And maybe I don't fully like it. > I th

Re: T[new]

2009-08-10 Thread Steven Schveighoffer
On Mon, 10 Aug 2009 15:21:48 -0400, Andrei Alexandrescu wrote: Steven Schveighoffer wrote: On Mon, 10 Aug 2009 14:38:24 -0400, Stewart Gordon wrote: Since nobody's yet asked What type would .dup and .idup return? The best choice I can see is to make .dup return T[new] and

Re: T[new]

2009-08-10 Thread Walter Bright
Jeremie Pelletier wrote: Walter: what will the string types be aliased to now: still immutable(char)[] or immutable(char)[new]? immutable(char)[] I think it would be best to have them use the array [new] type. The vast majority of uses will not need to be resizeable. Functions which do no

Re: T[new]

2009-08-10 Thread bearophile
dsimcha: > import std.stdio, std.perf; [...] > Results: > Direct: 226 > Indirect: 229 Thank you. Following your example I have tried to do a bit more realistic tests. // test1.d, for D2, Phobos import std.stdio: writeln; import std.perf: PerformanceCounter; final class TNew(T) { T* ptr;

Re: T[new]

2009-08-10 Thread Jarrett Billingsley
On Mon, Aug 10, 2009 at 6:53 PM, bearophile wrote: > If such tests are correct, then the new resizable arrays of D2 will indeed > have some performance penality (something like 13%-17% in this test, but > results may change with other array sizes). I don't see why that's a big problem. If you'

Re: T[new]

2009-08-11 Thread bearophile
Jarrett Billingsley: >I don't see why that's a big problem.< Like St Thomas I touch first and believe (maybe) later :-) Bye, bearophile

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 fo

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 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] I

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
s. W: Nobody complained about it with slices. FWIW, I found arrays in D1 so completely broken that I didn't it worth the effort to complain about every little detail. Everything about them was wrong. I consider them a textbook example of what not to do. My perception is that you're in a minority. Anyway, if there's something that T[new] can help with, let us know. Andrei

Re: T[new] misgivings

2009-10-15 Thread Robert Jacques
On Thu, 15 Oct 2009 22:55:07 -0400, 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

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. > > Parado

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 e

Re: T[new] misgivings

2009-10-15 Thread Rainer Deyke
found arrays in D1 so completely broken that I didn't it worth >> the effort to complain about every little detail. Everything about them >> was wrong. I consider them a textbook example of what not to do. > > My perception is that you're in a minority. Anyway, if t

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

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

Re: T[new] misgivings

2009-10-15 Thread Andrei Alexandrescu
. Structs have another. If the language absolutely needs to support both sets of attributes, I should at least be able to mix and match between them. So, what's the syntax for user-defined value types that are passed by reference going to be? ref struct? opPass? No need for new syntax. T[n

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&#

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

Re: T[new] misgivings

2009-10-15 Thread Rainer Deyke
Andrei Alexandrescu wrote: > Rainer Deyke wrote: >> So, what's the syntax for user-defined value types that are passed by >> reference going to be? ref struct? opPass? > > No need for new syntax. T[new] is a struct that has a pointer inside. Without new syntax, 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 Max Samukha
On Thu, 15 Oct 2009 21:55:07 -0500, Andrei Alexandrescu 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 statically: immutable(int)[] a =

Re: T[new] misgivings

2009-10-16 Thread Don
Max Samukha wrote: On Thu, 15 Oct 2009 21:55:07 -0500, Andrei Alexandrescu 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 statically: immutable(int)[]

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

Re: T[new] misgivings

2009-10-16 Thread Max Samukha
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 it already is one. x is given a pointer to the start of that block. >> x[] = y[]; does a memcpy, rega

Re: T[new] misgivings

2009-10-16 Thread Fawzi Mohamed
On 2009-10-16 11:49:12 +0200, Walter Bright 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 assignment. I also see T

Re: T[new] misgivings

2009-10-16 Thread Fawzi Mohamed
would be: If 'x' is T[new], then: x = y; _always_ copies y into a {length, capacity-specified block}, unless it already is one. x is given a pointer to the start of that block. x[] = y[]; does a memcpy, regardless of whether y is a T[new] or a T[]. Right. Assignment of a reference typ

Re: T[new] misgivings

2009-10-16 Thread Don
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 it already is one. x is given a pointer to the start of that block. x[] = y[]; does a memcpy, regardless of whether y is a T[new] or a T[]. Right. Assig

Re: T[new] misgivings

2009-10-16 Thread Max Samukha
On Fri, 16 Oct 2009 14:25:44 +0200, Don 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. > > void *data;

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 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 statically: imm

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 ex

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 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 Don
Andrei Alexandrescu wrote: Don wrote: Max Samukha wrote: On Thu, 15 Oct 2009 21:55:07 -0500, Andrei Alexandrescu 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 Don
Don wrote: Andrei Alexandrescu wrote: Don wrote: Max Samukha wrote: On Thu, 15 Oct 2009 21:55:07 -0500, Andrei Alexandrescu 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

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: in

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 mod

Re: T[new] misgivings

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

Re: T[new] misgivings

2009-10-16 Thread Denis Koroskin
real question is, what's the type of an array literal? If it's T[new] then you must reassign a reference to be consistent: int[new] a = arrayLiteral; int[new] b = a; // reassign reference foo(arrayLiteral); // a reference passed Else, invoke opAssign. And its semantics is not clear.

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 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 neve

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

Re: T[new] misgivings

2009-10-17 Thread Sergey Gromov
e common operation "I want to overwrite > whatever the array had with 1, 2, 3"? I can only presume there must be > an obvious and simple way to do so, and I thought a = [1, 2, 3] was the > obvious syntax to achieve that. I'd say a.replace([1, 2, 3]); > T[new] a; >

Re: T[new] misgivings

2009-10-17 Thread Sergey Gromov
wrote: >>>>>>> This goes into something more interesting that I thought of after >>>>>>> the conversation. Consider: >>>>>>> >>>>>>> T[new] a; >>>>>>> T[] b; >>>>>>> ... &

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

  1   2   3   >