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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,fccea7ca608399cd X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news.germany.com!xlned.com!feeder1.xlned.com!npeer.de.kpn-eurorings.net!npeer-ng1.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Mon, 19 Jan 2009 12:52:33 +0100 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.19 (Macintosh/20081209) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Vector of Vectors. References: <496e8418$0$25733$4d3efbfe@news.sover.net> <6t8gc1F9ej88U1@mid.individual.net> <497229d8$0$31340$9b4e6d93@newsspool4.arcor-online.net> <4973762d$0$32682$9b4e6d93@newsspool2.arcor-online.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <49746981$0$30231$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 19 Jan 2009 12:52:33 CET NNTP-Posting-Host: e34275ff.newsspool1.arcor-online.net X-Trace: DXC=HEXL;:IIeFJWDmlTRbh@=Iic==]BZ:afN4Fo<]lROoRA^YC2XCjHcbICW9^O>US0XI;9OJDO8_SKFNSZ1n^B98iJ_G1>0Z2n]BJ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:4407 Date: 2009-01-19T12:52:33+01:00 List-Id: Robert A Duff schrieb: > Georg Bauhaus writes: > >> Robert A Duff wrote: >> >>> The loop body is usually self explanatory. E.g: >> I wish it were, yes. A loop body _should_ be >> elf explanatory. FWIW, I have not seen a loop >> with just single statement in quite a while. >> Hope things are in different shape elsewhere. > > Not sure what you mean. I'm saying that Ada's current support for > iterators requires you to wrap the loop body in a named procedure. > The fact that people don't normally wrap loop bodies in procedures > (when using 'for' and 'while' loops) proves that doing so is a burden. But the fact that people don't normally bother to wrap loop bodies in procedures is not a prove that to do must be wrong, or that giving a loop name might not in fact be preferrable. Yes, it is work to find a good name but OTOH, it is considered good style, in particular in Ada culture, to Say What You Mean. AFAIK. I agree that the example you have given might show some silly formalism. But again, is this a typical scenario warranting more anonymity in Ada? Eiffel's new anonymous agents (access sub parameters with partially bound arguments) have met some criticism, too, BTW. Here is another example, one active and one passive iteration. Does the loop body deserve a captivating title? Then, maybe in the form of a named local procedure. function Active (Data: Vector; Threshold: Amount) return Amount is N: Positive; -- nth item Result: Amount; Item: Amount; begin Result := 0.0; N := 1; for Index in First_Index(Data) .. Last_Index(Data) loop Item := Element(Data, Index); if Item < Threshold then Result := ((N - 1) * Result + Item) / N; N := N + 1; else Skipped := Skipped + 1; end if; end loop; return Result; end Active; function Passive (Data: Vector; Threshold: Amount) return Amount is N: Positive; -- nth item Result: Amount; procedure Incremental_Average(Position: in Cursor) is Item: constant Amount := Element(Position); begin if Item < Threshold then Result := ((N - 1) * Result + Item) / N; N := N + 1; else Skipped := Skipped + 1; end if; end Incremental_Average; begin Result := 0.0; N := 1; Iterate(Data, Process => Incremental_Average'Access); return Result; end Passive; In Active, the new syntax you have suggested will shorten the loop body a bit, making Item's declaration in Active's declarative part unneccesary. But still, there will be a few lines left, worth a comment, at least? If so, then why not write a named body? Writing quick, anonymous, non-recursive lamdas is fun, but there is inherent danger in making them a language feature, I think. The danger is that they are going to be used like they are being used in Python, or Perl: spanning multiple lines, trying to be clever, avoid finding a name, write them once, never understand them again. See also the proliferation of anonymous access ;-) (I recall Vdim Gunko (I think) saying that adding named 'class pointers to the Qt4 (C++) binding is too much of a burdon...