From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Q: Trouble creating array and discriminated type Date: Sat, 21 Jan 2017 10:41:00 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <83409c51-59d3-4205-9eeb-5467de09f069@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 21 Jan 2017 09:39:21 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="c67d9a87afdd57b938139f15c13b3237"; logging-data="30019"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/uOt5paPQTDp5q6QGCt4M0HXO1VYNYPVg=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 In-Reply-To: <83409c51-59d3-4205-9eeb-5467de09f069@googlegroups.com> Cancel-Lock: sha1:H+ImahDKzNCXDP1SjBtxL2I9tOs= Xref: news.eternal-september.org comp.lang.ada:33110 Date: 2017-01-21T10:41:00+01:00 List-Id: On 01/20/2017 11:55 PM, b.mcguinness747@gmail.com wrote: > > I would appreciate help in solving these problems. One of the main purposes > for creating this code is for me to become more familiar with the Ada > language. I am much more familiar with Java, so I may not be looking at this > with an Ada mindset. It's very rare in Ada to have arrays with lower bounds of zero; code with lots of that usually reflects thinking warped by a poorly designed language in which all arrays have a lower bound of zero. Except when an array is serving as a map, it is usually more intuitive to use a lower bound of 1: we talk of being "1st in line" when at the head of a queue, or the 1st letter of a word. Another way to put this is that having a fixed lower bound forces a translation from the problem concept to the language index concept, introducing an opportunity for error. Ada allows the problem concept to be used as the index, eliminating that opportunity. My 1st (not 0th) programming job involved a language in which all arrays had lower bounds of 1, and we had data for the years 1600-1960. Translating from years to indices was a source of errors, so this is not just an academic problem. It's also useful sometimes to have non-numeric indices, so Ada allows enumeration types as indices, too. In addition to using index ranges that reflect your problem rather than the constraints of some language (I suspect your problem domain has identifying values other than 0 .. 677 for those indices), I'd also recommend eliminating all anonymous types; having to explicitly define and name all types often has a clarifying effect on one's thinking. This is especially true for anonymous access types, which have complicated rules no one completely understands. Gautier has explained a likely reason for your constant-array declaration errors, and Wright has shown the typical way such things are declared in Ada. It's probably a good idea to defer the discussion of discriminated records, constrained and unconstrained variables, and function results as objects until after you've digested what you've had so far. -- Jeff Carter "Mr. President, we must not allow a mine-shaft gap!" Dr. Strangelove 33