-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] Refer to the loop index in a *for .. of* loop #125
Comments
I think this looks very reasonable. It's a bit frustrating to not be able to do a more elegant thing involving possibly tuples and unpacking, as it is done in many other languages. I'm not sure it would be reasonable in Ada just because the involved effort is much larger, but I think it would be good to exhaust other ways (on paper of course), to justify that this is the best one for us. |
I seem to remember a syntactic sugar AI proposal in which you did
where |
Yes, it is the kind of alternative @raph-amiard is referring to above I think. I suspect it might be more complicated to support due to the problem of typing the pair in particular. Basically, it would require adding a new syntax in Ada whereas the syntax proposed in the RFC has the advantage of only needing a new attribute. It is more common as an extension. |
This syntax is consistent with the Ada 2022 syntax for Procedural Iterators, so would seem worth further investigation. See RM 5.5.3, with example:
|
Are procedural iterators already supported in GNAT? If so, I have no strong preference either ways. |
I don't believe they have been implemented yet, but this might be the impetus they need. |
Summary
A new attribute, possibly called
Loop_Index
, could be defined for the parameter of a for .. of loop to get the underlying index/cursor. Ideally, this would work both for loops over arrays, and loops using theIterable
aspect.Motivation
Currently, it is not possible to use for .. of loops in SPARK most of the time, as loop invariants generally need to refer to the underlying loop index/cursor etc. This is a shame as arguably for .. of loops are easier to read for programmers.
Caveats and alternatives
TBD
The text was updated successfully, but these errors were encountered: