🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #16

Re: Pointers in ALGOL

#16
From: Charles Lindsey
Date: Wed, 28 Oct 1992 10:57
55 lines
2635 bytes
In <1992Oct27.080658.28422@arb-phys.uni-dortmund.de> wb@arb-phys.uni-dortmund.de (Wilhelm B. Kloke) writes:

>In article <BwqwKt.AGI@nic.umass.edu> rmuller@neural.hampshire.edu (Rich Muller) writes:
>>in a lunch table discussion none of us could remember what facilities
>>ALGOL has for using pointers: declaring pointer variables,
>what ALGOL do you mean algol-60 or algol-68?

>I append an algol68 example which I got from C.H.Lindsey:
>(look for the REF keyword,REF [] BOOL is a pointer to a row of BOOL)

Well, its nice to see one's programs published on the net, but I do not
think this particular program illustrates the point about pointers (pun
accidental) very well.

>LOC[1:8, -6:15]BOOL allows;
	# a two-dimensional array #
>    REF [] BOOL allow = allows[row, ];

The purpose of this particular REF is just to allow you to speak about a
particular row of the two-dimensional 'allows' as if it were a one-dimensional
array - either for cleaner understanding, or better efficiency (only one
subscript needed) or both. Because you have declared a REF to it, you are
still allowed to assign to its elements

>        allow[res+row+1-i] := FALSE;
>        allow[res-row-1+i] := FALSE

Here is a more usual example of pointer use.

MODE LINK = STRUCT(INT val, REF LINK next);
REF LINK nolink = NIL;	# a convenient synonym for NIL #
LOC REF LINK start := nolink;

PROC insertatfront = (INT val) VOID:
	start := HEAP LINK := (val, start);

PROC insertatend = (INT val) VOID:
	BEGIN
	LOC REF REF LINK ptr := start;
	WHILE ptr :/=: nolink
	DO	ptr := next OF ptr
	OD;
	REF REF LINK (ptr) := HEAP LINK := (val, nolink)
	END;

The last example illustrates the so-called "3-ref trick" (the mode of ptr is
actually REF REF REF LINK, because it is a LOCal REF REF LINK variable). The
benefit is that you don't have to make a special case of when the list is
empty, as you would in Pascal. The bad news is that you have to cast 'ptr'
to the mode REF REF LINK (forces one dereferencing) in the last line to
ensure that you are assigning to the thing 'ptr' is pointing at, not to 'ptr'
itself. 

You can't do this sort of thing in Pascal, but you can do it in C if you are
VERY careful.
Technical Details
Message-ID: <chl.720269838@cs.man.ac.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!utcsri!torn!cunews!nrcnet0!bnrgate!bnr.co.uk!uknet!mucs!cs.man.ac.uk!chl
References: <BwqwKt.AGI@nic.umass.edu> <1992Oct27.080658.28422@arb-phys.uni-dortmund.de>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!utcsri!torn!cunews!nrcnet0!bnrgate!bnr.co.uk!uknet!mucs!cs.man.ac.uk!chl
From: chl@cs.man.ac.uk (Charles Lindsey)
Newsgroups: comp.lang.misc
Subject: Re: Pointers in ALGOL
Message-ID: <chl.720269838@cs.man.ac.uk>
Date: 28 Oct 92 10:57:18 GMT
References: <BwqwKt.AGI@nic.umass.edu> <1992Oct27.080658.28422@arb-phys.uni-dortmund.de>
Sender: newsman@cs.man.ac.uk
Lines: 55