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!mx02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: New to Ada, why these warning messages? Date: Thu, 31 Dec 2015 22:54:29 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Fri, 1 Jan 2016 05:51:53 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="caa759af2a9c666aec02942f6fe5abd6"; logging-data="13053"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18uWojEU+eIEbVvzHjk6osPq1FitahLMxA=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 In-Reply-To: X-Mozilla-News-Host: news://freenews.netfront.net Cancel-Lock: sha1:tqVW6t+AHNsAW8kMNSxO4Snao/A= Xref: news.eternal-september.org comp.lang.ada:28969 Date: 2015-12-31T22:54:29-07:00 List-Id: Botton explained the warnings you got, but a larger issue is that this is poor Ada and so not the best thing to be learning from. On 12/31/2015 07:19 PM, Dale Dellutri wrote: > > -- Some Paint arrays. The first one is initialized with a list > -- of colors. > A: AType := (Red, Red, Pink, Blue, Orange, Cherry, Indigo, Indigo); This is not a list. It's a positional array aggregate. > I: Integer; -- Loop index. As you've discovered, this is not the loop index. Loop indices are declared by the loop, are constant within the loop, and cease to exist when the loop is exited. Whoever wrote this was probably used to languages in which you had to declare a loop index like this, and hadn't learned how Ada works. > -- Use positions to set varioius values in various places. > B := (5 => Green, 2 => Orange, 6..8 => Indigo, 1|3|4 => Brown); This is a named array aggregate. > -- Set the entire array to Blue. > C := (AType'First .. AType'Last => Blue); This would be better written (Atype'range => Blue) or (Paint => Blue) > -- Print the position numbers, spaced out to align with the > -- the printouts of each of the arrays below. > for I in 1..N loop I would probably use for I in Atype'range loop to avoid using a "magic number", even in a case like this in which it's unlikely that a change to the constant won't also result in a change to the array range. > -- Print out the contents of each of A, B, and C. > for I in 1..N loop for I in A'range loop > Put(PNames(A(I)) & " "); > > for I in 1..N loop for I in B'range loop > Put(PNames(B(I)) & " "); > > for I in 1..N loop for I in C'range loop > Put(PNames(C(I)) & " "); Tying the loop index to the array using 'range makes it easier for the compiler to optimize away bounds checks. -- Jeff Carter "Strange women lying in ponds distributing swords is no basis for a system of government." Monty Python & the Holy Grail 66