comp.lang.ada
 help / color / mirror / Atom feed
* Default array base index
@ 2008-01-27 19:20 Scott Burson
  2008-01-27 19:36 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Scott Burson @ 2008-01-27 19:20 UTC (permalink / raw)


Hi,

I just came across this Wikipedia page:

http://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28array%29

which claims that the default base index for arrays in Ada is 1.  It
has been over 15 years since I have written any Ada, so my memory is
fuzzy, but what I recall is that there actually is no default: the
base index must always be specified explicitly when the array is
declared.  However, it does appear that Ada culture leans toward the
use of 1 as a default (for example, the language numbers the
dimensions of the array from 1 in attribute expressions).

Do you agree?

-- Scott



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Default array base index
  2008-01-27 19:20 Default array base index Scott Burson
@ 2008-01-27 19:36 ` Dmitry A. Kazakov
  2008-01-28  4:29   ` Scott Burson
  2008-01-27 20:40 ` (see below)
  2008-01-28 17:02 ` Adam Beneschan
  2 siblings, 1 reply; 6+ messages in thread
From: Dmitry A. Kazakov @ 2008-01-27 19:36 UTC (permalink / raw)


On Sun, 27 Jan 2008 11:20:59 -0800 (PST), Scott Burson wrote:

> I just came across this Wikipedia page:
> 
> http://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28array%29
> 
> which claims that the default base index for arrays in Ada is 1.  It
> has been over 15 years since I have written any Ada, so my memory is
> fuzzy, but what I recall is that there actually is no default: the
> base index must always be specified explicitly when the array is
> declared.

Actually both statements are wrong. As an example consider:

  Foo : array (Character) of Boo;

Here the base index is neither specified nor 1. It is NUL (character).

> However, it does appear that Ada culture leans toward the
> use of 1 as a default (for example, the language numbers the
> dimensions of the array from 1 in attribute expressions).

Maybe, when index is a signed integer type. But with modular integer types
0 as the lower bound looks quite natural. And for enumeration types the
issue makes no sense anyway.

What Ada culture leans toward is actually designing programs so that this
question would become irrelevant. An array of fixed size is defined over a
type or subtype which bounds determine the array bounds, so that there are
no illegal indices at all.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Default array base index
  2008-01-27 19:20 Default array base index Scott Burson
  2008-01-27 19:36 ` Dmitry A. Kazakov
@ 2008-01-27 20:40 ` (see below)
  2008-01-28 17:02 ` Adam Beneschan
  2 siblings, 0 replies; 6+ messages in thread
From: (see below) @ 2008-01-27 20:40 UTC (permalink / raw)


On 27/1/08 19:20, in article
1497d552-b826-4477-a181-4962a6d38c8c@i12g2000prf.googlegroups.com, "Scott
Burson" <FSet.SLB@gmail.com> wrote:

> http://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28array%29
> 
> which claims that the default base index for arrays in Ada is 1.

This is nonsense. I have fixed the Ada (and Pascal) info.

-- 
Bill Findlay
<surname><forename> chez blueyonder.co.uk





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Default array base index
  2008-01-27 19:36 ` Dmitry A. Kazakov
@ 2008-01-28  4:29   ` Scott Burson
  0 siblings, 0 replies; 6+ messages in thread
From: Scott Burson @ 2008-01-28  4:29 UTC (permalink / raw)


On Jan 27, 11:36 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> Actually both statements are wrong. As an example consider:
>
>   Foo : array (Character) of Boo;
>
> Here the base index is neither specified nor 1. It is NUL (character).

Hmm, I would say it is specified explicitly but indirectly, via the
definition of the base type.

> > However, it does appear that Ada culture leans toward the
> > use of 1 as a default (for example, the language numbers the
> > dimensions of the array from 1 in attribute expressions).
>
> Maybe, when index is a signed integer type. But with modular integer types
> 0 as the lower bound looks quite natural. And for enumeration types the
> issue makes no sense anyway.

Okay.

Thanks for the reply.

-- Scott



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Default array base index
  2008-01-27 19:20 Default array base index Scott Burson
  2008-01-27 19:36 ` Dmitry A. Kazakov
  2008-01-27 20:40 ` (see below)
@ 2008-01-28 17:02 ` Adam Beneschan
  2008-01-28 18:50   ` Dmitry A. Kazakov
  2 siblings, 1 reply; 6+ messages in thread
From: Adam Beneschan @ 2008-01-28 17:02 UTC (permalink / raw)


On Jan 27, 11:20 am, Scott Burson <FSet....@gmail.com> wrote:
> Hi,
>
> I just came across this Wikipedia page:
>
> http://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28a...
>
> which claims that the default base index for arrays in Ada is 1.  It
> has been over 15 years since I have written any Ada, so my memory is
> fuzzy, but what I recall is that there actually is no default: the
> base index must always be specified explicitly when the array is
> declared.  However, it does appear that Ada culture leans toward the
> use of 1 as a default (for example, the language numbers the
> dimensions of the array from 1 in attribute expressions).
>
> Do you agree?

There may be some small ways in which this is correct.  For example,
the predefined type String is defined with "Positive" as the index
subtype, which means you can't define a String subtype that starts at
index 0.  Of course, you can define one that starts at positive
integers larger than 1, but (without having read the article in
question) I suspect that this is part of a long-running debate over
whether it's "better" to start arrays and other sequences at 0 or 1
(as if there were one answer that fit every situation).  At least
once, I've seen articles in SIGPLAN or other places where an author
decided to number the sections, subsections, sub-subsections, etc., of
his article starting with section 0 instead of the more traditional 1,
apparently for no good reason except to declare which side of this
debate he was on.  So anyway, bases larger than 1 aren't really
relevant to this "culture" or stylistic issue.

Back to Ada, when I opened my Ada 95 RM to see if I could find other
predefined arrays, I did find this in A.9:

subtype Buffer_Type is
System.Storage_Elements.Storage_Array(1..Buffer_Size);

In general, though, I think the statement you quote is nonsense.  As
you mention, Ada doesn't really have a default base, and programmers
are free to choose whichever one suits the problem more.  In my own
code, when I don't have a particular reason to choose 1 or 0 as the
base, I tend to gravitate toward using 1, but I think that has less to
do with "Ada culture" and more to do with the fact that when I was one
year old and my mother started teaching me to count, she started with
"one" and not "zero".  Also, we always number everything else starting
with "first", "second", etc.; ever seen a baseball game played with
"zero-th base", "first base", and "second base"?  ("Who's on zero-
th?"  "Yes."
"I mean his name."  "Who."  "The guy on zero-th."  "Who."  "The zero-
th baseman."  "Who."  Just doesn't have the same ring to it.)  So it
isn't an "Ada culture" at all---it's the fact that using 1 seems more
natural, and that I get to use a language that gives me a choice,
rather than struggling with a low-level language like C that forces me
into unnatural behaviors like using 0 as the index base.

                               -- Adam






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Default array base index
  2008-01-28 17:02 ` Adam Beneschan
@ 2008-01-28 18:50   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry A. Kazakov @ 2008-01-28 18:50 UTC (permalink / raw)


On Mon, 28 Jan 2008 09:02:51 -0800 (PST), Adam Beneschan wrote:

> Also, we always number everything else starting
> with "first", "second", etc.; ever seen a baseball game played with
> "zero-th base", "first base", and "second base"?  ("Who's on zero-
> th?"  "Yes."
> "I mean his name."  "Who."  "The guy on zero-th."  "Who."  "The zero-
> th baseman."  "Who."  Just doesn't have the same ring to it.)  So it
> isn't an "Ada culture" at all---it's the fact that using 1 seems more
> natural, and that I get to use a language that gives me a choice,
> rather than struggling with a low-level language like C that forces me
> into unnatural behaviors like using 0 as the index base.

I think it boils down to the semantic difference between numerals and
ordinals. The problem arises when the same notation is attempted for both.
When 1 denotes an ordinal (the first) then 0 does not exist. There is
nothing before the first. But in the set of natural numbers 0 is the first
number. So 0 = 1. In some other set it could be the second or none. In Ada
the first ordinal used for arrays as sets is A'First, so the first element
is A(A'First), and not necessarily either A(1) or A(0).

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-01-28 18:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-27 19:20 Default array base index Scott Burson
2008-01-27 19:36 ` Dmitry A. Kazakov
2008-01-28  4:29   ` Scott Burson
2008-01-27 20:40 ` (see below)
2008-01-28 17:02 ` Adam Beneschan
2008-01-28 18:50   ` Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox