digitalmars.D - slicing mod proposal
- h3r3tic (8/8) Aug 19 2004 just a short note:
- Derek Parnell (14/25) Aug 19 2004 Its more explicit; tells the reader what we were intending to do.
- h3r3tic (6/21) Aug 19 2004 ok, i get ur point. thanks :]
- Sha Chancellor (5/11) Sep 26 2004 Slices return a pointer to a contiguous block of memory located inside
- h3r3tic (4/19) Sep 26 2004 Sure, but there was a discussion going around some time earlier
- Walter (4/12) Aug 19 2004 This is a common request. One reason it isn't done is it requires a runt...
just a short note: now we can do: (dmd 0.99) int[] b = a[0..length-2]; where a is another array of int... but isn't the 'length' ident redundant at all ? Python makes it implicit when the index is negative, so that a[0..-2] is a[0..length-2]. why dont we have it the same way ? it is very handy :)
Aug 19 2004
On Fri, 20 Aug 2004 04:46:47 +0200, h3r3tic wrote:just a short note: now we can do: (dmd 0.99) int[] b = a[0..length-2]; where a is another array of int... but isn't the 'length' ident redundant at all ? Python makes it implicit when the index is negative, so that a[0..-2] is a[0..length-2]. why dont we have it the same way ? it is very handy :)Its more explicit; tells the reader what we were intending to do. It helps trap some mistakes... int x,y; y = calc_size(a, z); . . . x = y - 1; b = a[1..x]; But if for some reason 'y' was zero or lower, this would be an error. It might not go detected if -ve values were allowed in slices. -- Derek Melbourne, Australia 20/Aug/04 12:50:38 PM
Aug 19 2004
Derek Parnell wrote:Its more explicit; tells the reader what we were intending to do. It helps trap some mistakes... int x,y; y = calc_size(a, z); . . . x = y - 1; b = a[1..x]; But if for some reason 'y' was zero or lower, this would be an error. It might not go detected if -ve values were allowed in slices.ok, i get ur point. thanks :] how about another thing though ? in python (yea, again ;]) i can say x[0:10:2] and that will create a sliced array with indexes 0, 2, 4, 6, 8, basically changing the stride of the slice. how bout that ? could be [a..b:c] or just [a..b..c] but i'd prefer the former
Aug 19 2004
In article <cg3rb4$2qij$1 digitaldaemon.com>, h3r3tic <h3r3tic dev.null> wrote:ok, i get ur point. thanks :] how about another thing though ? in python (yea, again ;]) i can say x[0:10:2] and that will create a sliced array with indexes 0, 2, 4, 6, 8, basically changing the stride of the slice. how bout that ? could be [a..b:c] or just [a..b..c] but i'd prefer the formerSlices return a pointer to a contiguous block of memory located inside the array you sliced. It doesn't allocated any new memory, it's just a pointer and a length. At least that's my understanding.
Sep 26 2004
Sha Chancellor wrote:In article <cg3rb4$2qij$1 digitaldaemon.com>, h3r3tic <h3r3tic dev.null> wrote:Sure, but there was a discussion going around some time earlier (relative to my old post) proposing interleaved arrays (even for multidimensional arrays) and this would just fit nicely with that concept.ok, i get ur point. thanks :] how about another thing though ? in python (yea, again ;]) i can say x[0:10:2] and that will create a sliced array with indexes 0, 2, 4, 6, 8, basically changing the stride of the slice. how bout that ? could be [a..b:c] or just [a..b..c] but i'd prefer the formerSlices return a pointer to a contiguous block of memory located inside the array you sliced. It doesn't allocated any new memory, it's just a pointer and a length. At least that's my understanding.
Sep 26 2004
"h3r3tic" <h3r3tic dev.null> wrote in message news:cg3omi$2p2q$1 digitaldaemon.com...just a short note: now we can do: (dmd 0.99) int[] b = a[0..length-2]; where a is another array of int... but isn't the 'length' ident redundant at all ? Python makes it implicit when the index is negative, so that a[0..-2] is a[0..length-2]. why dont we have it the same way ? it is very handy :)This is a common request. One reason it isn't done is it requires a runtime check, and people really like their arrays to be fast!
Aug 19 2004