Interesting Algol 68 idiom: UPB a[@1]
chris hermansen
clhermansen@gmail.com
Fri Jan 16 18:49:46 GMT 2026
Good morning, everyone,
On Fri, Jan 16, 2026 at 1:26 AM Jose E. Marchesi <jemarch@gnu.org> wrote:
>
> > I think I'm missing something...
> >
> > On Thu, Jan 15, 2026, 11:34 Jose E. Marchesi <jemarch@gnu.org> wrote:
> >
> >>
> >> Hello people!
> >>
> >> Just wanted to share a nice idiom I learned while porting the ELLA
> >> sources.
> >>
> >> The usual way to iterated over the elements of a multiple with the
> >> intention of indexing them is:
> >>
> >>
> >> for i from LWB a to UPB a do ... a[i] ... od
> >>
> >> This can be a bit cumbersome. The following shorter version is not
> >> valid, because the lower bound of the multiple `a' may not be 1:
> >>
> >> for i to UPB a do ... a[i] ... od
> >>
> >> This is also not correct, for the same reason:
> >>
> >> for i to ELEMS a do ... a[i] ... od
> >>
> >> What I learned in ELLA is that you can do:
> >>
> >> for i to UPB a[@1] do ... a[i] ... od
> >>
> >
> > Doesn't that have to be
> >
> > for i to UPB a[@1] do ... a[i + LWB a - 1] ... od
> >
> > ¿?
>
> Yes I meant to say a[@1][i] in the body.
>
Ah ok, that is interesting.
>
> >
> >
> >> It is short, and clear.
> >>
> >> I am actually tempted to put a fixed check in the compiler to compile it
> >> optimally so a trimmer doesn't get allocated.
>
I guess I would ask "what's the gain"? Seems to me you're exchanging a
straightforward mental pattern
for i from LWB a to UPB a
do
... a[i] ...
... a[i] ...
od
with something that's not so straightforward
for i to UPB a[@1]
do
... a[@1][i] ...
... a[@1][i] ...
od
I definitely find the latter harder to keyboard!
>>
> >> Hope this is useful.
> >> Salud!
It's an interesting thing to think about. I can speculate that there might
be circumstances where knowing the element number in the list of elements
examined (1st, 2nd, etc) is more useful than knowing the index value into
the array (5, 6, 7), especially if your stride is not by 1.
--
Chris Hermansen · clhermansen "at" gmail "dot" com
C'est ma façon de parler.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/algol68/attachments/20260116/96776a88/attachment.htm>
More information about the Algol68
mailing list