Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 27 |
Nodes: | 6 (0 / 6) |
Uptime: | 38:51:20 |
Calls: | 631 |
Calls today: | 2 |
Files: | 1,187 |
D/L today: |
23 files (29,781K bytes) |
Messages: | 174,060 |
Is that a Genie bug (or may I be missing something)...?
ASSERT (snake ISNT NIL);
ASSERT (head OF snake ISNT NIL);
coord OF head OF snake := new_coord;
1
a68g: runtime error: 1: attempt to access NIL name of mode REF SEGMENT,
in VOID closed-clause starting at "BEGIN" ...
On 27/09/2025 16:28, Janis Papanagnou wrote:
Is that a Genie bug (or may I be missing something)...?
"Missing" is intrinsically more likely, but "bug" is far
from impossible!
ASSERT (snake ISNT NIL);
ASSERT (head OF snake ISNT NIL);
coord OF head OF snake := new_coord;
1
a68g: runtime error: 1: attempt to access NIL name of mode REF SEGMENT,
in VOID closed-clause starting at "BEGIN" ...
"NIL" usually needs a cast in such contexts; in list or tree
processing, "snake" [or whatever] would usually /point/ to "NIL" rather
than /be/ "NIL" for an empty list.
That's why people usually declare
something like "REF SNAKE nilsnake = NIL;", then test "snake" for being "nilsnake" rather than "NIL".
Or you may have been careful about the mode of "snake"!
The other main possibility is that you've somehow
managed to switch off assertions.
HTH!
On 27/09/2025 16:28, Janis Papanagnou wrote:
ASSERT (snake ISNT NIL);
ASSERT (head OF snake ISNT NIL);
"NIL" usually needs a cast in such contexts ...
On Sat, 27 Sep 2025 20:50:41 +0100, I wrote:
"NIL" usually needs a cast in such contexts ...Then lack of same would cause a compile-time error, not a run-time error.
Changing the assert to ASSERT (REF SEGMENT (head OF snake) ISNT NIL); triggers an error though, so this is the essential hint! - Thanks.
The usual case would be that "snake" is a "REF REF SEGMENT",Or you may have been careful about the mode of "snake"!Don't know what you mean here.
On 27/09/2025 21:38, Janis Papanagnou wrote:
Changing the assert to ASSERT (REF SEGMENT (head OF snake) ISNT NIL);
triggers an error though, so this is the essential hint! - Thanks.
Yes, but "ASSERT (head OF snake ISNT REF SEGMENT (NIL))" would
have had the same effect; and then you find yourself repeating
"REF SEGMENT (NIL))" all over the place, and it becomes obvious that declaring "REF SEGMENT nilsnake = NIL;" allows you to save typing and
make the code clearer.
[...]
The usual case would be that "snake" is a "REF REF SEGMENT",Or you may have been careful about the mode of "snake"!Don't know what you mean here.
declared and initialised by "REF SEGMENT snake := nilsnake" [or, if
you prefer, "... := NIL;"], but there are contexts, such as procedure parameters, where the mode could be "REF SEGMENT", your test would
have been correct, and we would have had to look elsewhere for the
bug. I couldn't tell for sure from the program fragment you gave.
[Also, for all I knew, "snake" could have been a "REF REF REF SEGMENT",
as arises naturally in queue processing or in deleting items from the
middle of lists.] But, of course, common errors are more usual than
rare ones!
On 27/09/2025 21:47, Lawrence DrCOOliveiro wrote:
On Sat, 27 Sep 2025 20:50:41 +0100, Andy Walker wrote:
Then lack of same would cause a compile-time error, not a run-time
On 27/09/2025 16:28, Janis Papanagnou wrote:
ASSERT (snake ISNT NIL);
ASSERT (head OF snake ISNT NIL);
"NIL" usually needs a cast in such contexts ...
error.
No it wouldn't.
[...] My planned approach was that I reduce that
plethora of casts to separate superfluous ones from the necessary,
then homogenize the access methods to something more sensible; the introduction of a dedicated nil-constant may happen at that end.
In decades of programming it was never necessary to use triple-REFs.
I thought in Algol-68, coercion ambiguities were syntax errors.
The mode
of NIL is unspecified (beyond rCLREF-somethingrCY), so the context needs to completely specify the mode. The rCL:=:rCY and rCL:rea:rCY operators are defined so
that one operand is a strong syntactic position (is that term?) the other
one is soft. I guess if one operand is NIL, then that side must always be soft.
On 28/09/2025 00:19, Janis Papanagnou wrote:
[...] My planned approach was that I reduce that
plethora of casts to separate superfluous ones from the necessary,
then homogenize the access methods to something more sensible; the
introduction of a dedicated nil-constant may happen at that end.
With respect, I think this is backwards.
[...] If you
start with the nil-constants, the code is always clear and simple,
and you scarcely need any casts at all. [...]
In decades of programming it was never necessary to use triple-REFs.
I doubt whether it is ever /necessary/. [After all, we had
decades of programming when the main languages didn't even have
pointers.] But if you need to delete elements from the middle of
lists, it's much easier with a triple ref than with alternatives,
such as two pointers chasing each other down the lists, with all
manner of special cases.
If I inspect my Algol 68 textbook from the 1970's [...]
I've never had any problem with linked-list operations implemented
with REF REF functions arguments. (Neither in imperative programmed
form nor in a functional programmed form.) That's actually how I've
learned it. - I would think that introducing an unnecessary level of
REF would rather complicate comprehensibility. (Mileages may vary.)
I basically agree with that. But, that said, I'm obviously not used
to these castings and the user-defined type-specific NIL definitions.
My intention here was to get a better feeling for this approach.
If I inspect my Algol 68 textbook from the 1970's I also cannot find
a single use of such a code pattern. - Concerning my use of Algol 68
I'm very biased by its contents, and by the university teaching I
got. - There was just a single context type for such REF casts, and
no "own" 'nil' ever required.
In article <10bbp43$2fsef$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
I basically agree with that. But, that said, I'm obviously not used
to these castings and the user-defined type-specific NIL definitions.
My intention here was to get a better feeling for this approach.
If I inspect my Algol 68 textbook from the 1970's I also cannot find
a single use of such a code pattern. - Concerning my use of Algol 68
I'm very biased by its contents, and by the university teaching I
got. - There was just a single context type for such REF casts, and
no "own" 'nil' ever required.
The ALGOL 68-R Users Guide gives an example of a linked list type:
MODE LINK = STRUCT(INT item, REF LINK next);
It recommends declaring a null reference for the end of the list:
REF LINK empty = NIL;
The reason why this is preferable is that it enables us to test for the
end of the chain by means of the clause
next OF d IS empty
The mode of 'empty' causes 'next OF d' to be dereferenced to REF LINK
There's a copy of the guide at
https://github.com/coolbikerdad/Algol-68-Publications/blob/main/Algol68-R%20Users%20Guide.pdf