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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.165.75 with SMTP id o72mr8090666ioe.38.1513900014428; Thu, 21 Dec 2017 15:46:54 -0800 (PST) X-Received: by 10.157.88.6 with SMTP id r6mr173659oth.6.1513900014284; Thu, 21 Dec 2017 15:46:54 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!paganini.bofh.team!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!g80no1281426itg.0!news-out.google.com!b73ni4086ita.0!nntp.google.com!i6no1274858itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 21 Dec 2017 15:46:54 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=68.147.43.80; posting-account=GO34ygoAAABjKWQJiUlszgvYtyWwgCPW NNTP-Posting-Host: 68.147.43.80 References: <0d33e631-e63d-4346-ac95-5eec72127f4f@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: syntaxic exploration From: bj.mooremr@gmail.com Injection-Date: Thu, 21 Dec 2017 23:46:54 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:49579 Date: 2017-12-21T15:46:54-08:00 List-Id: On Thursday, December 21, 2017 at 12:18:39 AM UTC-7, Randy Brukardt wrote: > "Mehdi Saada" <00120260a@gmail.com> wrote in message > news:0d33e631-e63d-4346-ac95-5eec72127f4f@googlegroups.com... > > I'm being modelizing polynomes. I've got those two things: > > p_poly_v1_g.adb:51:21: iterable name cannot be a discriminant-dependent > > component of a mutable object > > Ah ? So I can't write that ? > > return RESULTAT : T_POLYNOME := POLY do > > for ELEMENT of RESULTAT.COEF loop > > Correct. You can't write this, because the iterable item could disappear in > the body of the loop. (If someone assigned a different value to the mutable > variable.) This is the same rule as used for renames (you can't rename this > component, either, for the same reason). > > ... > > I've got that too: > > p_poly_v1_g.adb:59:86: selector name should be identifier or "others" > > > > return RES: T_POLYNOME := > > (T_DEGRE'MAX(POLY_A.DEGRE,POLY_B.DEGRE),POLY_A.COEF'Range => POLY_A.COEF, > > others => Nulle) do > > > > I thought X'Range was strictly equivalent to X'First..X'Last ? > > 'Range is rather a wart in the language; it can only be used in a few > specific places. That's because X'Range is neither a subtype constraint nor > a value, and those are the only things with general rules. > > However, an aggregate choice is one the places that 'Range can be used, so > you're obviously doing something else wrong. (Which I can't see given the > partial code here.) > > Randy. I've been thinking lately that its a bit of a wart that 'Range or at least range syntax cant be used in more places. Specifically, I have been thinking of container iteration. It is currently awkward to iterate a subset of a container, given two cursors, a start and and end cursor. for a discrete subtype, we can express in Ada; for I in 5 .. 10 loop ... end loop Where the bounds of iteration can be a subset of the values of a subtype. It seems one ought to be able to do the same with cursors. for Position in Cursor1 .. Cursor2 loop list (Position) := ... end loop Note: This currently isn't legal in Ada. Otherwise, one has to write a while loop, which is a bit awkward. Position : Cursor := Cursor1; Iteration_Loop : loop List (Position) := ... exit Iteration_Loop when Position := Cursor2; Next (Position); end loop; One can almost do this with the current containers, with Ada 2012 iterator syntax because they generally have an Iterate primitive that accepts a start cursor. eg. for I in List.Iterate(Start => Cursor1) loop List (I) := ... end loop; But we currently do not have Iterate primitives in the standard containers that also accept an End cursor, so these calls allow one to start somewhere in the middle of a container and iterate to the end, but not to stop earlier. It seems like it would be relatively easy to add such calls. Then we could write; for I in List.Iterate(Start => Cursor1, Finish => Cursor2) loop List (I) := ... end loop; Perhaps the intent was to use exit to exit the loop earlier when you hit the second cursor. for I in List.Iterate(Start => Cursor1) loop List (I) := ... exit when I = Cursor2; end loop; I think that's somewhat satisfactory. But I still think it would be nice to take this one step further and be able to add syntactic sugar to express this with range syntax, as shown in the example above. I don't know how useful this would be, or how easy it would be to add to the language, but one place I would use it is when trying to iterate through containers in parallel where workers are each given a subset of the container by providing each worker with a start and end cursor. Brad