|
Prev: [anouncement] MingGW release for the GNU Ada Project
Next: ANN: GNAT/GPL Solaris 10: 2007-solaris-x86
From: Scott Burson on 27 Jan 2008 14:20 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
From: Dmitry A. Kazakov on 27 Jan 2008 14:36 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
From: (see below) on 27 Jan 2008 15:40 On 27/1/08 19:20, in article 1497d552-b826-4477-a181-4962a6d38c8c(a)i12g2000prf.googlegroups.com, "Scott Burson" <FSet.SLB(a)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
From: Scott Burson on 27 Jan 2008 23:29 On Jan 27, 11:36 am, "Dmitry A. Kazakov" <mail...(a)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
From: Adam Beneschan on 28 Jan 2008 12:02 On Jan 27, 11:20 am, Scott Burson <FSet....(a)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
|
Next
|
Last
Pages: 1 2 Prev: [anouncement] MingGW release for the GNU Ada Project Next: ANN: GNAT/GPL Solaris 10: 2007-solaris-x86 |