From: bj.mooremr@gmail.com
Subject: Re: syntaxic exploration
Date: Thu, 21 Dec 2017 15:46:54 -0800 (PST)
Date: 2017-12-21T15:46:54-08:00 [thread overview]
Message-ID: <b81c7f6f-dda7-4cd1-a9c6-953d0d30e7d4@googlegroups.com> (raw)
In-Reply-To: <p1fn8e$iud$1@franka.jacob-sparre.dk>
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
next prev parent reply other threads:[~2017-12-21 23:46 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-20 17:28 syntaxic exploration Mehdi Saada
2017-12-20 17:32 ` Mehdi Saada
2017-12-20 20:08 ` Niklas Holsti
2017-12-20 22:18 ` Mehdi Saada
2017-12-20 22:45 ` Mehdi Saada
2017-12-21 7:24 ` Randy Brukardt
2017-12-21 7:44 ` Niklas Holsti
2017-12-21 7:21 ` Randy Brukardt
2017-12-21 16:24 ` Jeffrey R. Carter
2017-12-22 5:01 ` Robert Eachus
2017-12-22 21:15 ` Simon Clubley
2017-12-22 22:11 ` Niklas Holsti
2017-12-22 22:51 ` Dmitry A. Kazakov
2017-12-23 7:15 ` Niklas Holsti
2017-12-23 16:23 ` Jeffrey R. Carter
2017-12-24 3:37 ` Robert Eachus
2017-12-24 13:39 ` Niklas Holsti
2017-12-24 13:32 ` Niklas Holsti
2017-12-25 13:40 ` Jeffrey R. Carter
2017-12-25 14:42 ` Mehdi Saada
2017-12-25 17:03 ` Dmitry A. Kazakov
2017-12-25 18:27 ` Niklas Holsti
2017-12-25 20:12 ` Jacob Sparre Andersen
2017-12-20 20:05 ` Niklas Holsti
2017-12-20 22:48 ` Mehdi Saada
2017-12-20 23:39 ` Mehdi Saada
2017-12-21 0:35 ` Mehdi Saada
2017-12-21 7:18 ` Randy Brukardt
2017-12-21 19:23 ` G. B.
2017-12-21 23:46 ` bj.mooremr [this message]
2017-12-22 23:45 ` Randy Brukardt
2017-12-22 13:31 ` Mehdi Saada
2017-12-22 18:00 ` Mehdi Saada
2017-12-22 18:27 ` Niklas Holsti
2017-12-22 20:25 ` Mehdi Saada
2017-12-22 22:33 ` Niklas Holsti
2017-12-23 1:47 ` Mehdi Saada
2017-12-23 7:17 ` Niklas Holsti
2017-12-23 11:23 ` Mehdi Saada
2017-12-23 11:39 ` Mehdi Saada
2017-12-23 12:09 ` Niklas Holsti
2017-12-23 12:12 ` Mehdi Saada
2017-12-23 12:16 ` Mehdi Saada
2017-12-23 13:04 ` Niklas Holsti
2017-12-23 14:02 ` Mehdi Saada
2017-12-23 14:46 ` Mehdi Saada
2017-12-23 15:03 ` Mehdi Saada
2017-12-23 22:11 ` Niklas Holsti
2017-12-24 0:55 ` Mehdi Saada
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox