Re: Feature suggestion: in-place append to array

2010-04-01 Thread bearophile
Mike S: > I figured the eager ones wouldn't be a problem, but I wondered whether > the lazy ones might be a pain. Guess not, so cool. :) Lazy ones are just a struct/class instance that contains an opApply method (or that follows the Range protocol methods). Very easy. > As far as D3 goes tho

Re: Feature suggestion: in-place append to array

2010-04-01 Thread Steven Schveighoffer
On Thu, 01 Apr 2010 11:01:38 -0400, Mike S wrote: I suppose the abstraction makes it a QOI though, so depending on the compiler and GC used in the future it could become a question again. As it stands, I'm less interested in its precise current state and more interested in keeping an ey

Re: Feature suggestion: in-place append to array

2010-04-01 Thread Andrei Alexandrescu
Mike S wrote: bearophile wrote: How difficult do you think that would be for the compiler devs to implement in the semantic sense? Assuming it can be done without major hardship or compromising the design of the language, that would be really cool.< They are easy to implement. Even the lazy

Re: Feature suggestion: in-place append to array

2010-04-01 Thread Mike S
Steven Schveighoffer wrote: Its abstracted to the GC, but the current GC is well defined. If you request to allocate blocks with length of a power of 2 under a page, you will get exactly that length, all the way down to 16 bytes. If you request to allocate a page or greater, you get a contigu

Re: Feature suggestion: in-place append to array

2010-04-01 Thread Mike S
bearophile wrote: How difficult do you think that would be for the compiler devs to implement in the semantic sense? Assuming it can be done without major hardship or compromising the design of the language, that would be really cool.< They are easy to implement. Even the lazy ones. See Shed

Re: Feature suggestion: in-place append to array

2010-04-01 Thread Steven Schveighoffer
On Thu, 01 Apr 2010 01:41:02 -0400, Mike S wrote: Steven Schveighoffer wrote: > What do you mean by nondeterministic? It's very deterministic, just not always easy to determine ;) However, given enough context, it's really easy to determine. When I say deterministic, I'm referring t

Re: Feature suggestion: in-place append to array

2010-04-01 Thread bearophile
Mike S: >Well, writing code Java-style is certainly no problem for game devs,< Right. Here I was talking about D uses more in general, sorry, like young programmers coming out of the university. >it'll still be a long time before someone actually starts from scratch to >write a new kernel usi

Re: Feature suggestion: in-place append to array

2010-03-31 Thread Mike S
Steven Schveighoffer wrote: > What do you mean by nondeterministic? It's very deterministic, just not always easy to determine ;) However, given enough context, it's really easy to determine. When I say deterministic, I'm referring to determinism from the user's point of view, where the al

Re: Feature suggestion: in-place append to array

2010-03-31 Thread Steven Schveighoffer
On Wed, 31 Mar 2010 17:57:07 -0400, Mike S wrote: Steven Schveighoffer wrote: You are correct, setCapacity ensures that *at least* the given number of elements will be available for appending. I planned on making the function a property (but a bug would not allow that), the original int

Re: Feature suggestion: in-place append to array

2010-03-31 Thread Mike S
bearophile wrote: The short D1 history shows that designers of small games are willing to use D. Some game designers seem almost desperate to find an usable language simpler than C++. So I agree with you that D2 can be designed keeping an eye at game designers too. But that's very demanding pe

Re: Feature suggestion: in-place append to array

2010-03-31 Thread bearophile
Mike S: >the needs of game programmers should be taken seriously while considering D's >evolution:< The short D1 history shows that designers of small games are willing to use D. Some game designers seem almost desperate to find an usable language simpler than C++. So I agree with you that D2

Re: Feature suggestion: in-place append to array

2010-03-31 Thread Mike S
bearophile wrote: Mike S: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html It's a nice read. I don't see them switching to D soon. If you whisper them that D is based on a GC they will run away screaming :-) Bye, bearophile Hah...well, there's a reason I'm still just look

Re: Feature suggestion: in-place append to array

2010-03-31 Thread bearophile
Mike S: > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html It's a nice read. I don't see them switching to D soon. If you whisper them that D is based on a GC they will run away screaming :-) Bye, bearophile

Re: Feature suggestion: in-place append to array

2010-03-31 Thread Mike S
Steven Schveighoffer wrote: You are correct, setCapacity ensures that *at least* the given number of elements will be available for appending. I planned on making the function a property (but a bug would not allow that), the original intended usage was: a.capacity = 1; Reserve doesn't

Re: Feature suggestion: in-place append to array

2010-03-04 Thread Steven Schveighoffer
On Thu, 04 Mar 2010 13:38:30 -0500, grauzone wrote: Steven Schveighoffer wrote: So it probably should be marked as unsafe. Doesn't it conform to Andrei's ideas about memory safety? It can stomp over other data, but it can't be used to subvert the type system. I think the idea is that a

Re: Feature suggestion: in-place append to array

2010-03-04 Thread grauzone
Steven Schveighoffer wrote: On Thu, 04 Mar 2010 12:43:32 -0500, grauzone wrote: Steven Schveighoffer wrote: On Thu, 04 Mar 2010 11:43:27 -0500, grauzone wrote: Some sort of "resetAndReuse" function to clear an array, but enabling to reuse the old memory would be nice: int[] a = data; a =

Re: Feature suggestion: in-place append to array

2010-03-04 Thread Steven Schveighoffer
On Thu, 04 Mar 2010 12:43:32 -0500, grauzone wrote: Steven Schveighoffer wrote: On Thu, 04 Mar 2010 11:43:27 -0500, grauzone wrote: Some sort of "resetAndReuse" function to clear an array, but enabling to reuse the old memory would be nice: int[] a = data; a = null; a ~= 1; //reallocates

Re: Feature suggestion: in-place append to array

2010-03-04 Thread Steven Schveighoffer
On Thu, 04 Mar 2010 12:29:25 -0500, Clemens wrote: Steven Schveighoffer Wrote: int[] a; a.setCapacity(1); // pre-allocate at least 1 elements. I would prefer the name reserve(). It has precedent in the STL, and the method doesn't actually always set the capacity, only if the curre

Re: Feature suggestion: in-place append to array

2010-03-04 Thread grauzone
Steven Schveighoffer wrote: On Thu, 04 Mar 2010 11:43:27 -0500, grauzone wrote: Some sort of "resetAndReuse" function to clear an array, but enabling to reuse the old memory would be nice: int[] a = data; a = null; a ~= 1; //reallocates (of course) a.length = 0; a ~= 1; //will reallocate (fo

Re: Feature suggestion: in-place append to array

2010-03-04 Thread Clemens
Steven Schveighoffer Wrote: > int[] a; > a.setCapacity(1); // pre-allocate at least 1 elements. I would prefer the name reserve(). It has precedent in the STL, and the method doesn't actually always set the capacity, only if the current capacity is less then the argument. Even then it m

Re: Feature suggestion: in-place append to array

2010-03-04 Thread Steven Schveighoffer
On Thu, 04 Mar 2010 11:43:27 -0500, grauzone wrote: Some sort of "resetAndReuse" function to clear an array, but enabling to reuse the old memory would be nice: int[] a = data; a = null; a ~= 1; //reallocates (of course) a.length = 0; a ~= 1; //will reallocate (for safety), used not to reall

Re: Feature suggestion: in-place append to array

2010-03-04 Thread grauzone
Steven Schveighoffer wrote: On Thu, 04 Mar 2010 04:02:46 -0500, KF wrote: I hope this is the right place to post it. In my work, I often need to add elements at the end of dynamic arrays and remove them from the end. This incremental changes would most conveniently be performed by a~=e for ad

Re: Feature suggestion: in-place append to array

2010-03-04 Thread Steven Schveighoffer
On Thu, 04 Mar 2010 04:02:46 -0500, KF wrote: I hope this is the right place to post it. In my work, I often need to add elements at the end of dynamic arrays and remove them from the end. This incremental changes would most conveniently be performed by a~=e for addition of e at the end of a,

Feature suggestion: in-place append to array

2010-03-04 Thread KF
I hope this is the right place to post it. In my work, I often need to add elements at the end of dynamic arrays and remove them from the end. This incremental changes would most conveniently be performed by a~=e for addition of e at the end of a, and say a=a[0..$-1]. Unfortunately, ~= always cre