Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: TIMTOWTDI -- so long as it's not my way

by cat2014 (Monk)
on Jan 16, 2001 at 10:04 UTC ( [id://52168]=note: print w/replies, xml ) Need Help??


in reply to TIMTOWTDI -- so long as it's not my way

one of the worst things that's ever happened to me was learning pascal as my first serious language. to this day, 90% of the time when i want to get the first element from an array, i automatically type $array[1]. then i spend 3 minutes looking at the funky output, remember that i always screw up arrays, and go fix it. you'd think that after about 2 years of doing this i'd stop.

is there even any other language which uses array[1] instead of array[0] to access the first element?

Replies are listed 'Best First'.
Re: TIMTOWTDI -- so long as it's not my way
by Dominus (Parson) on Jan 16, 2001 at 11:53 UTC
    Says cat2014:
    is there even any other language which uses array[1] instead of array[0] to access the first element?

    Fortran.

Re: Re: TIMTOWTDI -- so long as it's not my way
by jepri (Parson) on Jan 16, 2001 at 13:47 UTC
    Actually most versions of BASIC brought out by MS used array(1) as the base. But in an unparalleled moment of clarity they included a command that allow you to set the first index of the array to 1 OR 0. I think it was called OPTION BASE

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

Re: Re: TIMTOWTDI -- so long as it's not my way
by jynx (Priest) on Jan 18, 2001 at 06:08 UTC
    While we're completely off-topic (and no one's around anymore to --me for bringing up this one ; ),

    If i remember correctly Ada allows any base for the first element of an array. So you could have an array from 64 to 128 if you wanted.

    That would be really confusing if you had different array bounds for every array!

    jynx

Re: Re: TIMTOWTDI -- so long as it's not my way
by t'mo (Pilgrim) on Jan 17, 2001 at 01:13 UTC

    (Since your question leads us off the Perl path anyway...) Smalltalk does, but with different syntax. For example, take the following Array of Strings:

    | temp | temp := #('one' 'two' 'three'). Transcript show: (temp at: 1).

    The line Transcript show: (temp at: 1). will print the string "one".

    My training was with C++/C, and on the new job, we get to use Smalltalk. So I've been having the opposite problem that you've been having. :-)

Re: Re: TIMTOWTDI -- so long as it's not my way
by yakko (Friar) on Jan 16, 2001 at 11:39 UTC
    Some dialects of BASIC use one-based arrays, IIRC... I think FPBASIC is one such BASIC, tho I'm too lazy to fire my Apple up to test it right now. :o)

    --
    Me spell chucker work grate. Need grandma chicken.

Re: Re: TIMTOWTDI -- so long as it's not my way
by beppu (Hermit) on Jan 17, 2001 at 00:08 UTC
    PostgreSQL is a more contemporary example of something that uses 1-based arrays. Although it's contrary to the concept of relational databases, PostgreSQL lets one define columns that can contain arrays of basic types (like an array of int). These arrays are 1-based.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://52168]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-19 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found