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!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: A few questions Date: Wed, 4 Nov 2015 19:20:42 -0600 Organization: JSA Research & Innovation Message-ID: References: NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1446686443 9060 24.196.82.226 (5 Nov 2015 01:20:43 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 5 Nov 2015 01:20:43 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:28218 Date: 2015-11-04T19:20:42-06:00 List-Id: "Simon Wright" wrote in message news:lybnb9lote.fsf@pushface.org... > Simon Wright writes: > >> "Randy Brukardt" writes: >> >>> "Simon Wright" wrote in message >>> news:ly611kmh1g.fsf@pushface.org... >>> ... >>>> I wrote the attached, using generalized iteration, which bears a >>>> strong resemblance to the standard container iteration (the names >>>> bear too strong a resemblance! but this way you can see the >>>> commonality). >>> >>> I suspect you could have written this in a lot simpler >>> fashion. Something similar to the Prime_Numbers iterator found in the >>> ACATS foundation (F552A00, look in the support subdirectory, >>> specifically >>> http://www.ada-auth.org/cgi-bin/cvsweb.cgi/acats/support/f552a00.a) >>> would be a starting point. (Thanks again to Brad Moore for creating >>> this foundation and the associated ACATS tests to give all Ada >>> implementers something to use as a correct example of iterators.) >> >> Great pointer. Though I think the Date case would be a bit more >> complicated, because you couldn't constrain a Date_Set by Times or >> Durations. > > And I was hoping to write > > with Ada.Text_IO; > with F552A00_Prime_Numbers; > procedure Primes is > begin > for P of F552A00_Prime_Numbers.Prime_Number_Set'(Max_Value => 31) > loop > Ada.Text_IO.Put_Line (P'Img); > end loop; > end Primes; > > but (surprise) > > primes.adb:5:08: cannot iterate over "Prime_Number_Set" Prime_Number_Set is (directly) an iterator, so you use "in" to iterate over it: for P in F552A00_Prime_Numbers.Prime_Number_Set'(Max_Value => 31) loop The "of" form is for iterating over an array or a container whose type has the Default_Iterator aspect (which gives the iterator to use). I can hear the head slap from here. ;-) Randy.