ID:180434
 
How can I define an indexed list to start at 0 instead of 1? If I can't, consider this a request for version 3. :-)
On 6/19/01 5:49 am Skysaw wrote:
How can I define an indexed list to start at 0 instead of 1? If I can't, consider this a request for version 3. :-)

listvar[index+1] ;)

Current DM doesn't support it directly. Don't you just hate "off by one" errors?
In response to Shadowdarke
On 6/19/01 6:03 am Shadowdarke wrote:
On 6/19/01 5:49 am Skysaw wrote:
How can I define an indexed list to start at 0 instead of 1? If I can't, consider this a request for version 3. :-)

listvar[index+1] ;)

Current DM doesn't support it directly. Don't you just hate "off by one" errors?

Personally I really like the index starting at 1.

More bugs than can be counted in the world have been caused by indexes starting at zero. It doesn't go along with how people think, and the only reason it's likely to feel awkward is because of how other languages do it.

However, other languages also require braces and semi-colons, and that you walk off the end of your strings all the time and crash!
In response to Deadron
On 6/19/01 8:48 am Deadron wrote:
On 6/19/01 6:03 am Shadowdarke wrote:
On 6/19/01 5:49 am Skysaw wrote:
How can I define an indexed list to start at 0 instead of 1? If I can't, consider this a request for version 3. :-)

listvar[index+1] ;)

Current DM doesn't support it directly. Don't you just hate "off by one" errors?

Personally I really like the index starting at 1.

More bugs than can be counted in the world have been caused by indexes starting at zero. It doesn't go along with how people think, and the only reason it's likely to feel awkward is because of how other languages do it.

However, other languages also require braces and semi-colons, and that you walk off the end of your strings all the time and crash!

I have no problem with lists that start with one, and many occasions (perhaps most) call for it. I do have a problem with not being able to override that when programming elegance dictates it should begin with something else.
In response to Skysaw
On 6/19/01 9:05 am Skysaw wrote:
I have no problem with lists that start with one, and many occasions (perhaps most) call for it. I do have a problem with not being able to override that when programming elegance dictates it should begin with something else.

Hmm I'm all for DM being the best language and if this option makes it a better language that would be fine...on the other hand, I don't know if any zero-based language that let's you choose to start at 1, so screw them!
In response to Deadron
On 6/19/01 11:52 am Deadron wrote:
I don't know if any zero-based language that let's you choose to start at 1, so screw them!

One of the old BASIC interpreters (QBASIC I think?) had a command called option base. I think that did what Skysaw is talking about... if you really want to consider BASIC a language? :P

I never used option base. I thought it was kind of superfluous even then, back when memory was measured in Kilobytes instead of Megabytes and every spare byte your code conserved was treasured.
How can I define an indexed list to start at 0 instead of 1? If I can't, consider this a request for version 3. :-)

You could define a datum that holds a list, and write a couple simple procs to access it via your preferred numbering scheme.

E.g.,

myWackyList.Get(0)

would return

myWackyList.hiddenList[1]

Easy as cookie. Of course, you lose all the handy list access notations... :)
In response to Gughunter
On 6/19/01 1:15 pm Gughunter wrote:
How can I define an indexed list to start at 0 instead of 1? If I can't, consider this a request for version 3. :-)

You could define a datum that holds a list, and write a couple simple procs to access it via your preferred numbering scheme.

E.g.,

myWackyList.Get(0)

would return

myWackyList.hiddenList[1]

Easy as cookie. Of course, you lose all the handy list access notations... :)

Ok, I was looking for a way to make my code more elegant, not more "wacky." :-)
In response to Shadowdarke
I never used option base. I thought it was kind of superfluous even then, back when memory was measured in Kilobytes instead of Megabytes and every spare byte your code conserved was treasured.

Well, it's a matter of -standards-, not of efficiency...

We geeks can spout out popular algorithms word for word...it might take some mathematical mindwork (or heck, it's easy to forget if you spend 8 hours a day working C++) to convert array base from 0 to the -very- nonstandard 1