www.digitalmars.com         C & C++   DMDScript  

D - possible doc bug?

reply Lewis <dethbomb hotmail.com> writes:
in docs for Slice it says

b = a[1..3];	a[1..3] is a 2 element array consisting of a[1] and a[2]

shouldnt it be....

b = a[1..3];	a[1..3] is a 3 element array consisting of a[1] and a[2] and a[3]
Dec 18 2003
parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
Looks correct to me.

Those originating from C++ are inculcated in the STL notion of an asymmetric
range, which has the syntax [f, t), which indicates that the range consists
of everything from f up to, but not including t. It's pretty much the same
situation as we know in C with array dimensions, e.g. the valid indexes in
int ar[10] are 0 - 9.

"Lewis" <dethbomb hotmail.com> wrote in message
news:brt1ft$1a9b$1 digitaldaemon.com...
 in docs for Slice it says

 b = a[1..3]; a[1..3] is a 2 element array consisting of a[1] and a[2]

 shouldnt it be....

 b = a[1..3]; a[1..3] is a 3 element array consisting of a[1] and a[2] and


Dec 18 2003
parent reply Lewis <dethbomb hotmail.com> writes:
Matthew wrote:

  It's pretty much the same
 situation as we know in C with array dimensions, e.g. the valid indexes in
 int ar[10] are 0 - 9.
 

i can understand the 0 - 9 part, it makes sense , as thats how most 0 based array index's work, which is why it makes no sense then to slice the array with a[8 .. 10] (to get the last 2 index's) it should be [8 .. 9] i say this is something that should be changed... (just my opinion). it does make the syntax [3 .. arr.length] easier but it should be [3 .. arr.length - 1] to be correct ;)
Dec 18 2003
next sibling parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
Neither is more "right" than the other in an absolute sense. It's the same
argument as to whether to count from 0 or 1.

It's just the case that counting from 0, and specifying 1-past-the-post
range ends is more usable in most circumstances. I'd rate you having less
chance of getting this changed than the world's organised religions doing a
corporate merger next spring.

;)

Matthew

"Lewis" <dethbomb hotmail.com> wrote in message
news:brt5l5$1h9l$1 digitaldaemon.com...
 Matthew wrote:

   It's pretty much the same
 situation as we know in C with array dimensions, e.g. the valid indexes


 int ar[10] are 0 - 9.

i can understand the 0 - 9 part, it makes sense , as thats how most 0

 array index's work, which is why it makes no sense then to slice the array

 a[8 .. 10] (to get the last 2 index's) it should be [8 .. 9]
 i say this is something that should be changed... (just my opinion).

 it does make the syntax [3 .. arr.length] easier but it should be
 [3 .. arr.length - 1] to be correct ;)

Dec 18 2003
parent reply Lewis <dethbomb hotmail.com> writes:
Matthew wrote:

 Neither is more "right" than the other in an absolute sense. It's the same
 argument as to whether to count from 0 or 1.
 
 It's just the case that counting from 0, and specifying 1-past-the-post
 range ends is more usable in most circumstances. I'd rate you having less
 chance of getting this changed than the world's organised religions doing a
 corporate merger next spring.
 
 ;)
 
 Matthew
 

Your probably right :) I just need to adapt my way of thinking is all, when i see the slice operator my brain wants to see "To" as in: a[] = Slice(3 To 9); or ('LowerBound' To 'UpperBound') when its really: a[] = Slice( StartIndex To 'Index + 1' )
Dec 18 2003
parent J Anderson <REMOVEanderson badmama.com.au> writes:
Lewis wrote:

 Matthew wrote:

 Neither is more "right" than the other in an absolute sense. It's the 
 same
 argument as to whether to count from 0 or 1.

 It's just the case that counting from 0, and specifying 1-past-the-post
 range ends is more usable in most circumstances. I'd rate you having 
 less
 chance of getting this changed than the world's organised religions 
 doing a
 corporate merger next spring.

 ;)

 Matthew

Your probably right :) I just need to adapt my way of thinking is all, when i see the slice operator my brain wants to see "To" as in: a[] = Slice(3 To 9); or ('LowerBound' To 'UpperBound') when its really: a[] = Slice( StartIndex To 'Index + 1' )

Funny, I had this same problem!
Dec 18 2003
prev sibling parent reply Felix <Felix_member pathlink.com> writes:
Maybe arrays should be inedexed starting with 1... I know it is not the C/C++
way, neither one of mathematics (almost every array begins with a0) but is more
intuitive.


In article <brt5l5$1h9l$1 digitaldaemon.com>, Lewis says...
Matthew wrote:

  It's pretty much the same
 situation as we know in C with array dimensions, e.g. the valid indexes in
 int ar[10] are 0 - 9.
 

i can understand the 0 - 9 part, it makes sense , as thats how most 0 based array index's work, which is why it makes no sense then to slice the array with a[8 .. 10] (to get the last 2 index's) it should be [8 .. 9] i say this is something that should be changed... (just my opinion). it does make the syntax [3 .. arr.length] easier but it should be [3 .. arr.length - 1] to be correct ;)

Dec 19 2003
next sibling parent reply Lewis <dethbomb hotmail.com> writes:
Felix wrote:

 Maybe arrays should be inedexed starting with 1... I know it is not the C/C++
 way, neither one of mathematics (almost every array begins with a0) but is more
 intuitive.

I have no problems with arrays being 0 indexed, its just the slice operator doesnt follow the same philosophy. To grab the first two elements should be a[] = b[0 .. 1] or b[lbound .. ubound] but not a[] = b[0 .. 2] ... its unintuitive to me because the start index is 0 based but the ending index is 0 + 1 based ( or something like that), But as was stated, it seems for compatibility reasons an such it wouldnt be wise to be changed. (no global religion for us! :) )
Dec 19 2003
parent reply "Sean L. Palmer" <palmer.sean verizon.net> writes:
We had a huge debate about this a very long time ago and Walter won.  ;)

If anything, I like your suggestion about basing arrays on one less than the
current spec.  You're suggesting both making slice syntax inclusive on both
ends (which already lost) and to also make arrays 1-based, which is very
unlikely to change since most of us (everybody with a C, C++, Pascal, Java,
or C#, or assembly background) like 0-based arrays.  It's all in what you
were exposed to first as to what seems intuitive.  It's not so terribly
difficult to rewire that part of your brain.  You just have to try it for a
while, and after a while you "just get it".  ;)

Sean

"Lewis" <dethbomb hotmail.com> wrote in message
news:bruevq$f9l$1 digitaldaemon.com...
 Felix wrote:

 Maybe arrays should be inedexed starting with 1... I know it is not the


 way, neither one of mathematics (almost every array begins with a0) but


 intuitive.

I have no problems with arrays being 0 indexed, its just the slice

 doesnt follow the same philosophy. To grab the first two elements
   should be a[] = b[0 .. 1] or b[lbound .. ubound] but not a[] = b[0 .. 2]

 its unintuitive to me because the start index is 0 based but the ending

 0 + 1 based ( or something like that), But as was stated, it seems for
 compatibility reasons an such it wouldnt be wise to be changed. (no global
 religion for us! :) )

Dec 19 2003
next sibling parent Lewis <dethbomb hotmail.com> writes:
Sean L. Palmer wrote:
 We had a huge debate about this a very long time ago and Walter won.  ;)
 
 If anything, I like your suggestion about basing arrays on one less than the
 current spec.  You're suggesting both making slice syntax inclusive on both
 ends (which already lost) and to also make arrays 1-based, which is very
 unlikely to change since most of us (everybody with a C, C++, Pascal, Java,
 or C#, or assembly background) like 0-based arrays.  It's all in what you
 were exposed to first as to what seems intuitive.  It's not so terribly
 difficult to rewire that part of your brain.  You just have to try it for a
 while, and after a while you "just get it".  ;)
 
 Sean

that walter he always wins aye ? ;) actually i want to clarify that i definetly would *hate* to see arrays 1 based note the following quote: "I have no problems with arrays being 0 indexed" this should have said "i have no problems with arrays being 0 based" would have been better way to state it... In vb the collections are almost all 1 based [1 to count] and the arrays are 0 based [0 to count - 1] by default (what i always used) but you could cause all arrays to be 1 based with a compiler flag... in fact they are the same as COM safearray's. But all that aside, i would lobby hard against 1 based arrays, but the slice operator should follow the same philosophy of 0 based arrays in my opinion, But again that is easier to get used to [startindex .. endindex + 1] than a 1 based array would be *shudders*
Dec 19 2003
prev sibling next sibling parent reply Felix <Felix_member pathlink.com> writes:
Thanks for your advice. It is nice, as any Christmas present should be... ;)
I expressed only one (very doubtful: "maybe" even for me...)
I'll by another brain...
Nevermind, me too used to index by zero, till starting to work seriously under
Matlab (engineering). Here index is one-based...

To short the debate, it was the most strightforward way to link the slicing with
the definition. But I don't want to be devil's advocate...

Anyway (i start my hollyday) I wold like to wish you (and to all other people on
the forum) Merry Christmas! and Happy New Year! A 2004-index based "Long live
the humankind!"

;)
No harm.





In article <brukho$nb5$1 digitaldaemon.com>, Sean L. Palmer says...
We had a huge debate about this a very long time ago and Walter won.  ;)

If anything, I like your suggestion about basing arrays on one less than the
current spec.  You're suggesting both making slice syntax inclusive on both
ends (which already lost) and to also make arrays 1-based, which is very
unlikely to change since most of us (everybody with a C, C++, Pascal, Java,
or C#, or assembly background) like 0-based arrays.  It's all in what you
were exposed to first as to what seems intuitive.  It's not so terribly
difficult to rewire that part of your brain.  You just have to try it for a
while, and after a while you "just get it".  ;)

Sean

"Lewis" <dethbomb hotmail.com> wrote in message
news:bruevq$f9l$1 digitaldaemon.com...
 Felix wrote:

 Maybe arrays should be inedexed starting with 1... I know it is not the


 way, neither one of mathematics (almost every array begins with a0) but


 intuitive.

I have no problems with arrays being 0 indexed, its just the slice

 doesnt follow the same philosophy. To grab the first two elements
   should be a[] = b[0 .. 1] or b[lbound .. ubound] but not a[] = b[0 .. 2]

 its unintuitive to me because the start index is 0 based but the ending

 0 + 1 based ( or something like that), But as was stated, it seems for
 compatibility reasons an such it wouldnt be wise to be changed. (no global
 religion for us! :) )


Dec 19 2003
parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
"Felix" <Felix_member pathlink.com> wrote in message
news:bruqs5$10a8$1 digitaldaemon.com...
 Anyway (i start my hollyday) I wold like to wish you (and to all other

 the forum) Merry Christmas! and Happy New Year! A 2004-index based "Long

 the humankind!"

Yeah, I get two weeks off, with nothing to do! Woohoo! Maybe I'll get the latest DMD and play around.
 ;)
 No harm.

No harm, no foul! ;) Sean
Dec 19 2003
prev sibling parent reply Felix <Felix_member pathlink.com> writes:
Thanks for your advice. It is nice, as any Christmas present should be... ;)
I expressed only one (very doubtful: "maybe" even for me...)
I'll bUy another brain...
Nevermind, me too used to index by zero, till starting to work seriously under
Matlab (engineering). Here index is one-based...

To short the debate, it was the most strightforward way to link the slicing with
the definition. But I don't want to be devil's advocate...

Anyway (i start my hollyday) I wold like to wish you (and to all other people on
the forum) Merry Christmas! and Happy New Year! A 2004-index based "Long live
the humankind!"

;)
No harm.





In article <brukho$nb5$1 digitaldaemon.com>, Sean L. Palmer says...
We had a huge debate about this a very long time ago and Walter won.  ;)

If anything, I like your suggestion about basing arrays on one less than the
current spec.  You're suggesting both making slice syntax inclusive on both
ends (which already lost) and to also make arrays 1-based, which is very
unlikely to change since most of us (everybody with a C, C++, Pascal, Java,
or C#, or assembly background) like 0-based arrays.  It's all in what you
were exposed to first as to what seems intuitive.  It's not so terribly
difficult to rewire that part of your brain.  You just have to try it for a
while, and after a while you "just get it".  ;)

Sean

"Lewis" <dethbomb hotmail.com> wrote in message
news:bruevq$f9l$1 digitaldaemon.com...
 Felix wrote:

 Maybe arrays should be inedexed starting with 1... I know it is not the


 way, neither one of mathematics (almost every array begins with a0) but


 intuitive.

I have no problems with arrays being 0 indexed, its just the slice

 doesnt follow the same philosophy. To grab the first two elements
   should be a[] = b[0 .. 1] or b[lbound .. ubound] but not a[] = b[0 .. 2]

 its unintuitive to me because the start index is 0 based but the ending

 0 + 1 based ( or something like that), But as was stated, it seems for
 compatibility reasons an such it wouldnt be wise to be changed. (no global
 religion for us! :) )


Dec 19 2003
parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
 Anyway (i start my hollyday) I wold like to wish you (and to all other

 the forum) Merry Christmas! and Happy New Year! A 2004-index based "Long

 the humankind!"

You too, and to all the other D-programmers. I think 2004 will have some big things for D. :) Cheers everyone -- Matthew Wilson STLSoft moderator (http://www.stlsoft.org) Contributing editor, C/C++ Users Journal (www.synesis.com.au/articles.html#columns) "An Englishman by birth, a Yorkshireman by the grace of God" -- Michael Gibbs ---------------------------------------------------------------------------- ---
Dec 19 2003
parent "Carlos Santander B." <carlos8294 msn.com> writes:
"Matthew" <matthew.hat stlsoft.dot.org> wrote in message
news:brvs3h$2jsp$1 digitaldaemon.com...
| > Anyway (i start my hollyday) I wold like to wish you (and to all other
| people on
| > the forum) Merry Christmas! and Happy New Year! A 2004-index based "Long
| live
| > the humankind!"
|
| You too, and to all the other D-programmers.
|
| I think 2004 will have some big things for D. :)
|
| Cheers everyone
|
|
|
| --
| Matthew Wilson
|
| STLSoft moderator (http://www.stlsoft.org)
| Contributing editor, C/C++ Users Journal
| (www.synesis.com.au/articles.html#columns)
|
| "An Englishman by birth, a Yorkshireman by the grace of God" -- Michael
| Gibbs
|
| --------------------------------------------------------------------------
--
| ---
|
|
|

I was planning to do it around the 23rd, 24th, but since you guys are doing
it now, me too.

Happy holidays to you all, let 2004 be a very good year for all of us, and
for D too ;).

-----------------------
Carlos Santander Bernal
Dec 19 2003
prev sibling parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
 Maybe arrays should be inedexed starting with 1... I know it is not the

 way, neither one of mathematics (almost every array begins with a0) but is

 intuitive.

To whom? Once again, this is something that you need to be careful not to colour with your own opinion/experience. In reality, arrays aren't intuitive to anyone, any more than English, French, Spanish, treble clefs, C++, mathematics, or any of the other wonderful but arbitrary creations of man. You're far better to play with it, get used to it, and forget the days when it seemed foreign. :) Matthew
 In article <brt5l5$1h9l$1 digitaldaemon.com>, Lewis says...
Matthew wrote:

  It's pretty much the same
 situation as we know in C with array dimensions, e.g. the valid indexes



 int ar[10] are 0 - 9.

i can understand the 0 - 9 part, it makes sense , as thats how most 0


array index's work, which is why it makes no sense then to slice the


a[8 .. 10] (to get the last 2 index's) it should be [8 .. 9]
i say this is something that should be changed... (just my opinion).

it does make the syntax [3 .. arr.length] easier but it should be
[3 .. arr.length - 1] to be correct ;)


Dec 19 2003