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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,51bff7cd4c35a15d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.219.170 with SMTP id pp10mr1125826pbc.1.1338497904513; Thu, 31 May 2012 13:58:24 -0700 (PDT) Path: l9ni4970pbj.0!nntp.google.com!news2.google.com!postnews.google.com!j9g2000vbk.googlegroups.com!not-for-mail From: tonyg Newsgroups: comp.lang.ada Subject: Re: Ada2012 : In praise of 'for ... of ... loop'... Date: Thu, 31 May 2012 13:58:24 -0700 (PDT) Organization: http://groups.google.com Message-ID: <53841cff-1dc1-47ec-8778-4a3f1c3ba55e@j9g2000vbk.googlegroups.com> References: <74e4e6b5-20bd-4388-b4a0-dfbecc8070be@googlegroups.com> <4fc4e51d$0$6566$9b4e6d93@newsspool4.arcor-online.net> <371a4b67-1969-4cd5-90f4-d58a9b276f29@googlegroups.com> <8e00262b-8ff5-4862-b4a4-d19465a389b1@googlegroups.com> NNTP-Posting-Host: 77.98.243.142 Mime-Version: 1.0 X-Trace: posting.google.com 1338497904 32149 127.0.0.1 (31 May 2012 20:58:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 31 May 2012 20:58:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: j9g2000vbk.googlegroups.com; posting-host=77.98.243.142; posting-account=28F2IwkAAACL1Z5nRC-dE7zuvWdbWC7P User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0,gzip(gfe) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-05-31T13:58:24-07:00 List-Id: On May 31, 2:09=A0pm, Martin wrote: > On Wednesday, May 30, 2012 8:30:21 PM UTC+1, Jeffrey Carter wrote: > > On 05/30/2012 01:10 AM, Martin wrote: > > > > =A0 =A0 =A0 =A0for Comment of Header_Comments loop > > > =A0 =A0 =A0 =A0 =A0 Put_Line (File, Comment_Str& =A0Comment); > > > =A0 =A0 =A0 =A0end loop; > > > =A0 =A0 =A0 =A0if Include_Last_Saved_Time then > > > =A0 =A0 =A0 =A0 =A0 Put_Line (File, Comment_Str& =A0"Last saved: "& = =A0Image (Date =3D> =A0Clock)); > > > =A0 =A0 =A0 =A0end if; > > > =A0 =A0 =A0 =A0for Section of This.Sections loop > > > =A0 =A0 =A0 =A0 =A0 Put_Line (File, "["& =A0To_String (Section.Name)&= =A0"]"); > > > =A0 =A0 =A0 =A0 =A0 for Pair of Section.Pairs loop > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0Put_Line (File, To_String (Pair.Key)& =A0"= =3D"& =A0To_String (Pair.Value)); > > > =A0 =A0 =A0 =A0 =A0 end loop; > > > =A0 =A0 =A0 =A0end loop; > > > This uses 2 inline "for" loops, one containing a nested "for loop". > > > > =A0 =A0 =A0 =A0Close (File); > > > =A0 =A0 exception > > > =A0 =A0 =A0 =A0-- implementation detail > > > =A0 =A0 end Save; > > > > what we used to have (mocked up!): > > > This uses vector iterators. > > > While this is a nice feature, I don't think it's worth the added langua= ge > > complexity. > > > In general, using "for" loops will be clearer than using iterators. In = the case > > of vectors (or unbounded arrays, to use their correct name), one can it= erate > > over them using "for" loops, and the use of iterators for an array abst= raction > > is a questionable practice: > > > for I in Header_Comments.First_Index .. Header_Comments.Last_Index loop > > =A0 =A0 Put_Line (File, Comment_Str & Header_Comments.Element (I) ); > > end loop; > > > if ... then > > =A0 =A0 ... > > end if; > > > for I in This.Sections.First_Index .. This.Sections.Last_Index loop > > =A0 =A0 Section :=3D This.Sections.Element (I); > > =A0 =A0 Put_Line ... > > > =A0 =A0 for J in Section.Pairs.First_Index .. Section.Pairs.Last_Index = loop > > =A0 =A0 =A0 =A0Pair :=3D Section.Pairs.Element (J); > > =A0 =A0 =A0 =A0Put_Line ... > > =A0 =A0 end loop; > > end loop; > > > I think this is equally clear and requires no additional language compl= exity. > > > Had your example used sets or maps it would have been a stronger argume= nt. > > > -- > > Jeff Carter > > "He didn't get that nose from playing ping-pong." > > Never Give a Sucker an Even Break > > 110 > > > --- Posted via news://freenews.netfront.net/ - Complaints to n...@netfr= ont.net --- > > Sorry, I just find that full of "noise" these days...to many characters t= hat are just repeated. and 'Section' and 'Pairs' need to be declared somewh= ere too. I know you can get rid of the repetition with some 'renames' or a = nested subprogram but that's just "noise" and makes more work for the reade= r. > > Aside from the benefits Pascal mentions, the new syntax offers both reada= bility *and writability* which is a bit of a departure for the language ;-) > > -- Martin very interesting. Thanks for the example and explaining it well Martin. I really appreciate this because it does not come easily to me, but once its there it sticks and is very useful. Is this going to go into a wiki, maybe the danish ada mafia would host a gems like section in there.