Occasionally I had the demand to create arbitrarily nested arrays of
arrays (similar to the question in [*]). This requires something like [][]...[] SOMETYPE and the corresponding nested loops for processing
-a FOR i ...
-a-a-a ...
-a-a-a-a-a FOR j ...
-a-a-a-a-a-a-a FOR k ...
But these are static definitions and don't scale for arbitrary depth.
(The dimension/depth of nesting is defined during runtime at start!)
In the context of another language I had implemented such logic simply
by linearizing the arrays and the associated array index calculation.
An alternative approach could be to build the structures recursively
(with linked data structures) and with a recursive set of functions.
Now pondering what to do in Algol 68...
[...]
Or is there some code pattern [in Algol 68] that would simplify the
task without muddying the clarity of the algorithms?
I don't see how anyone can advise without knowing more about
what the actual, underlying, problem is. My personal inclination, from
a position of complete ignorance about what you're really trying to do,
would be to go for a recursive solution.
module counter_module
So, I was, like, thinking you guys were using FORTRAN.
But now I see "Algol" in the subject!
import itertools
import math
bases =[ 2, 3, 2, 2 ]
total_product = math.prod( bases )
ranges =[ range( b ) for b in bases ]
for digits in itertools.product( *reversed( ranges )):
print( *digits )
On 26/12/2025 11:25, Janis Papanagnou wrote:
Occasionally I had the demand to create arbitrarily nested arrays of
arrays (similar to the question in [*]). This requires something like
[][]...[] SOMETYPE and the corresponding nested loops for processing
-a-a FOR i ...
-a-a-a-a ...
-a-a-a-a-a-a FOR j ...
-a-a-a-a-a-a-a-a FOR k ...
But these are static definitions and don't scale for arbitrary depth.
(The dimension/depth of nesting is defined during runtime at start!)
-a-a-a-aSee below!
In the context of another language I had implemented such logic simply
by linearizing the arrays and the associated array index calculation.
An alternative approach could be to build the structures recursively
(with linked data structures) and with a recursive set of functions.
Now pondering what to do in Algol 68...
-a-a-a-aI don't see how anyone can advise without knowing more about
what the actual, underlying, problem is.
My personal inclination, from
a position of complete ignorance about what you're really trying to do,
would be to go for a recursive solution.
[...]
Or is there some code pattern [in Algol 68] that would simplify the
task without muddying the clarity of the algorithms?
-a-a-a-a[This is the "See below"!]-a You say that the depth is determined
at "start".-a An alternative could be to construct an A68 program of the right depth "on the fly".-a A simple program goes through constructing
the right number of nested "FOR" loops, or whatever.-a [...]
-a-a-a-aI should add that my advice is worth no more than yourCOre paying for it, and also that my charges are tripled over the holiday period.
Merry New Year!
ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
So, I was, like, thinking you guys were using FORTRAN.
But now I see "Algol" in the subject!
BEGIN
INT n = 4;
[1:4]INT bases;
bases := (2,3,2,2);
INT product := 1;
# Standard for loop #
FOR i FROM 1 TO n DO product := product * bases[i] OD;
FOR count FROM 0 TO product - 1 DO
INT temp := count;
[1:4]INT digits := (0,0,0,0);
INT j := 1;
WHILE j <= n DO
digits[j] := temp MOD bases[j];
temp := temp OVER bases[j];
j +:= 1
OD;
print((whole(digits[4], 0), " ", whole(digits[3], 0), " ",
whole(digits[2], 0), " ", whole(digits[1], 0), newline))
OD;
END
Occasionally I had the demand to create arbitrarily nested arrays of
arrays (similar to the question in [*]). This requires something like [][]...[] SOMETYPE and the corresponding nested loops for processing
-a FOR i ...
-a-a-a ...
-a-a-a-a-a FOR j ...
-a-a-a-a-a-a-a FOR k ...
But these are static definitions and don't scale for arbitrary depth.
(The dimension/depth of nesting is defined during runtime at start!)
In the context of another language I had implemented such logic simply
by linearizing the arrays and the associated array index calculation.
An alternative approach could be to build the structures recursively
(with linked data structures) and with a recursive set of functions.
Now pondering what to do in Algol 68...
The linearization appears to be the most simple (yet effective) way.
The recursive one may be conceptually cleaner (but has more overhead).
Or is there some code pattern [in Algol 68] that would simplify the
task without muddying the clarity of the algorithms?
Janis
PS: In my Algol 68 context the above written-a [][]...[] SOMETYPE-a is actually rather a more coherent-a [ , ,... , ] SOMETYPE-a sort of array (which makes the index-flattening simple).
[*] https://stackoverflow.com/questions/17479241/how-to-create-a-nested- array-of-arbitrary-depth-in-java
Occasionally I had the demand to create arbitrarily nested arrays of
arrays (similar to the question in [*]). This requires something like [][]...[] SOMETYPE and the corresponding nested loops for processing
FOR i ...
...
FOR j ...
FOR k ...
But these are static definitions and don't scale for arbitrary depth.
(The dimension/depth of nesting is defined during runtime at start!)
In the context of another language I had implemented such logic simply
by linearizing the arrays and the associated array index calculation.
An alternative approach could be to build the structures recursively
(with linked data structures) and with a recursive set of functions.
On 26/12/2025 11:25, Janis Papanagnou wrote:
[...]
This looked an intriguing problem for my dynamic language.
In the experiment below, such an array of considered an N-dimensional cuboid. Its size and shape is described by an N-element vector giving
the bounds of each dimension (assumed to be 1-based; N must be at least
1, and no bounds are empty).
[...]
At first it didn't look like this was a practical approach for Algol68
or any statically typed language.
[...]
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
[...]
Linearization seem to be best as implementaition. For typed
interface nice way is to use list (or vectors) as indices. If a
language has simple way of creating lists you could have code like
a([1, 2, 3, 4])
for accessing elements.
Concerning iteration, simple in-order
iteration basically needs to implement multiposition counter
with carries at appropriate points. Or you could expose
undelying linear structure. For exmple in Lisp there is
ROW-MAJOR-AREF to access elements of possibly multidimensional
array in lineare order and there is ARRAY-ROW-MAJOR-INDEX
to get linear index corresponding to given tuple of indices
(useful when one wants to deal with slices).
In any case, it all looks messy, whatever the language.
On Sun, 28 Dec 2025 15:32:36 +0000, bart wrote:
In any case, it all looks messy, whatever the language.
Look at the rCLodometer stylerCY example that Stefan Ram posted.
ranges =[ range( b ) for b in [ 2, 3, 2, 2 ]]
for digits in itertools.product( *reversed( ranges )): print( *digits )
On 28/12/2025 22:54, Lawrence DrCOOliveiro wrote:
On Sun, 28 Dec 2025 15:32:36 +0000, bart wrote:
In any case, it all looks messy, whatever the language.
Look at the rCLodometer stylerCY example that Stefan Ram posted.
That 'odometer' method was also used in the example I posted.
That's part of what I consider messy.
[...] I thought the abstraction would be sufficiently clear. :-/
(Especially since the Stackoverflow link I posted described it as
well.
[...]
Or is there some code pattern [in Algol 68] that would simplify the
task without muddying the clarity of the algorithms?
-a-a-a-a-a[This is the "See below"!]-a You say that the depth is determined >> at "start".-a An alternative could be to construct an A68 program of theThanks. But Yuck! - I'd prefer static Algol 68 code to introducing
right depth "on the fly".-a A simple program goes through constructing
the right number of nested "FOR" loops, or whatever.-a [...]
another level of software generation with dynamic creation of code.
[...]
OTOH, if you're inclined to read Usenet on a Sunday your potential fees
might be unjustified anyway. ;-)
On 28/12/2025 14:47, Janis Papanagnou wrote:
[...]
-a-a-a-a[...] Thunderbird makes
following links a somewhat tedious process -- since an upgrade a while
back [perhaps when it became a "snap" (grr!)] it no longer follows
things I click on, so I have to copy the link, switch to a browser,
paste the link, press "Enter" and switch back when finished -- so I do
it only when "necessary".
[...]
Or is there some code pattern [in Algol 68] that would simplify the
task without muddying the clarity of the algorithms?
-a-a-a-aI don't know of one.-a You can use operators and unions to
make some things more transparent, but you still can't, as far as I
can see, get to arbitrary numbers of subscripts.
OTOH, if you're
going the "odometer" route, operators to transform arbitrary arrays
of pseudo-subscripts into one "real" subscript or vv could be useful.
-a-a-a-a-a[This is the "See below"!]-a You say that the depth is determined >>> at "start".-a An alternative could be to construct an A68 program of the >>> right depth "on the fly".-a A simple program goes through constructingThanks. But Yuck! - I'd prefer static Algol 68 code to introducing
the right number of nested "FOR" loops, or whatever.-a [...]
another level of software generation with dynamic creation of code.
-a-a-a-aWell, yes.-a But I've become quite used to using A68G as a
"shell" language -- it takes a small fraction of a second to compile
and run a reasonable script.-a If we can have two-level grammars, we can surely have two-level programs!
On 2025-12-30 17:29, Andy Walker wrote:
On 28/12/2025 14:47, Janis Papanagnou wrote:
[...]
-a-a-a-a-a[...] Thunderbird makes
following links a somewhat tedious process -- since an upgrade a while
back [perhaps when it became a "snap" (grr!)] it no longer follows
things I click on, so I have to copy the link, switch to a browser,
paste the link, press "Enter" and switch back when finished -- so I do
it only when "necessary".
This is bad behavior [of Thunderbird]. Actually, I have all sorts of
issues with my new (snap-based) version of TB. Half of the issues is
directly related to snap and wrong design. But the links-thing works
in my TB; it opens a new tab in the last Firefox instance I used.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 54 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 17:44:41 |
| Calls: | 742 |
| Files: | 1,218 |
| D/L today: |
4 files (8,203K bytes) |
| Messages: | 184,414 |
| Posted today: | 1 |