Interesting Algol 68 idiom: UPB a[@1]
chris hermansen
clhermansen@gmail.com
Fri Jan 16 04:55:13 GMT 2026
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
¿?
> 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.
>
> Hope this is useful.
> Salud!
>
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/20260115/5857c1ae/attachment.htm>
More information about the Algol68
mailing list