Is there a way in Algol 68 that I can create an array indexed [0..1] of procedures to be initialized by an _identity_ declaration as 'p' below?
PROC g = BOOL : ... ;
PROC h = BOOL : ... ;
[] PROC BOOL p =
CASE n IN
( h, g ),
( g, h )
ESAC;
Like this code but array 'p' with indices 0..1 (instead of 1..2).
Declaring 'p' with [0:1] isn't possible it seems for the identity case
where a formal [] declarer seems necessary.
While an _assignment_ like
[0:1] PROC BOOL p := ... ;
is obviously possible.
On 01/11/2025 15:00, Janis Papanagnou wrote:
Is there a way in Algol 68 that I can create an array indexed [0..1] of
procedures to be initialized by an _identity_ declaration as 'p' below?
PROC g = BOOL : ... ;
PROC h = BOOL : ... ;
[] PROC BOOL p =
CASE n IN
( h, g ),
( g, h )
ESAC;
Like this code but array 'p' with indices 0..1 (instead of 1..2).
The problem is that "(h,g)" is an array indexed starting at 1.
So you need to re-base the array by using "[@0]".
The obvious place to put that is immediately after the "ESAC",
but A68G complains on the
perhaps spurious ground that the "[@0]"can only be applied to a row or similar.
I don't know whether this is also a true A68 limitation or a
minor A68G bug/divergence.
The simplest workaround seems to be to
declare "pp" in the way you've declared "p", and then declare
"[] PROC BOOL p = pp[@0];".
Declaring 'p' with [0:1] isn't possible it seems for the identity case
where a formal [] declarer seems necessary.
True. In "[] PROC BOOL p = whatever", "p" takes its bounds from
those of "whatever", so it's "whatever" rather than "p" that has to have
the bounds you want.
While an _assignment_ like
[0:1] PROC BOOL p := ... ;
is obviously possible.
It's possible, but you will still have problems unless "..." has
bounds "0:1". In cases similar to your code above, it might still be best
to create an object specifically of the correct type/mode, so starting at
1 by default and then re-basing that.
On 01.11.2025 21:54, Andy Walker wrote:[...]
I don't know whether this is also a true A68 limitation or a
minor A68G bug/divergence.
Maybe I'll also ask what Marcel thinks; specifically concerning Genie,
or generally concerning the standard. (Maybe it's an oversight; can't
tell.)
The simplest workaround seems to be to
declare "pp" in the way you've declared "p", and then declare
"[] PROC BOOL p = pp[@0];".
[...] In cases similar to your code above, it might still be best
to create an object specifically of the correct type/mode, so starting at
1 by default and then re-basing that.
On 01.11.2025 21:54, I wrote:
The simplest workaround seems to be toI had intended to avoid "spurious" declarations, but to keep the later
declare "pp" in the way you've declared "p", and then declare
"[] PROC BOOL p = pp[@0];".
code's logic clearer it might be worth to follow that path.
On 02/11/2025 06:33, Janis Papanagnou wrote:
On 01.11.2025 21:54, I wrote:
The simplest workaround seems to be toI had intended to avoid "spurious" declarations, but to keep the later
declare "pp" in the way you've declared "p", and then declare
"[] PROC BOOL p = pp[@0];".
code's logic clearer it might be worth to follow that path.
A slightly different approach would use a cast:
[] PROC BOOL p = [] PROC BOOL CASE ... ESAC [@0];
That avoids the extra declaration, but I'm unconvinced that it's as clear
-- good luck trying to explain how that all works to a class of students!
On 02/11/2025 11:10, Andy Walker wrote:
On 02/11/2025 06:33, Janis Papanagnou wrote:
On 01.11.2025 21:54, I wrote:
The simplest workaround seems to be toI had intended to avoid "spurious" declarations, but to keep the later
declare "pp" in the way you've declared "p", and then declare
"[] PROC BOOL p = pp[@0];".
code's logic clearer it might be worth to follow that path.
A slightly different approach would use a cast:
[] PROC BOOL p = [] PROC BOOL CASE ... ESAC [@0];
That avoids the extra declaration, but I'm unconvinced that it's as clear
-- good luck trying to explain how that all works to a class of students!
Is this a general problem when using a (...) constructor, in that the
natural bounds start from 1?
I couldn't get this to work:
[0:3]INT a := (10, 20, 30);
It prefers empty bounds, but those default to 1:. Using [0:] didn't
work. Trying that [@0] didn't work either, for example:
[0:3]INT a;
a := (10, 20, 30) [@0];
It seems a weak spot in the language.
[...]
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,075 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 94:28:55 |
| Calls: | 13,798 |
| Calls today: | 1 |
| Files: | 186,989 |
| D/L today: |
6,266 files (1,783M bytes) |
| Messages: | 2,438,400 |