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!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad.newshosting.com!newshosting.com!newspeer.monmouth.com!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Vector of Vectors. Date: Sun, 18 Jan 2009 16:29:39 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: 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> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1232314179 3948 192.74.137.71 (18 Jan 2009 21:29:39 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 18 Jan 2009 21:29:39 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:C28UPkKceOwSAX4MadojsjhoUzo= Xref: g2news2.google.com comp.lang.ada:4400 Date: 2009-01-18T16:29:39-05:00 List-Id: 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. I want to create procedures for exactly the code that represents a coherent abstraction -- and that's not necessarily the body of a loop. >> for Index in S'Range loop >> S(Index) := To_Upper_Case(S(Index)); >> end loop; >> >> Do you want me to call it "Convert_Current_Character_To_Upper_Case", >> and wrap it in a procedure by that name? > > No, but I think I'd prefer something like > > Iterate(S, Process => To_Upper_Case); Without the 'Access. ;-) Normally, the loop body needs access to some local variable (or parameter). Here's another example: Suppose we have a procedure to send a character to an output stream: procedure Put(Stream: in out ...; C: Character); And we want to write a procedure to send a String. So we write: procedure Put(Stream: in out ...; S : String) is begin for I in S'Range loop Put(Stream, S(I)); end loop; end Put; It would be silly to write: procedure Put(Stream: in out ...; S : String) is procedure Put(C: Character) is begin Put(Stream, C); end Put; begin for I in S'Range loop Put(S(I)); end loop; end Put; No matter what you call that inner Put, it doesn't deserve to be a named procedure at all. Note that it has to be nested, because it needs to refer to Stream -- we can't create a reusable one and put it in a library. But if we have a Vector of Characters, or Linked_List of Characters, instead of an array of Characters, we would be forced to write that silly nested procedure. Not sure whether we are agreeing or disagreeing, here... ;-) > That is, To_Upper_Case is a good name, already. > The loop above is a "for-all" loop, Index is used > for nothing but a concrete, clumsy, and---if you > will---redundant handle of the abstraction "for-all". > So why a detailed loop? I definitely agree with this part. The Index is conceptually unnecessary. Furthermore, the fact that arrays and Vectors use totally different syntax for iteration and element selection and so forth is a Bad Thing. Ideally, we want to say something like: for C: Character in S loop -- Whether S is an array, or some other sequence data structure -- not a named procedure end loop; - Bob