Path: utzoo!attcan!uunet!mcvax!ukc!mupsy!mucs!r1!chl From: chl@r1.uucp (Charles Lindsey) Newsgroups: comp.lang.misc Subject: Re: Alternatives to refs Message-ID: <5185@ux.cs.man.ac.uk> Date: 30 Nov 88 11:52:11 GMT References: <388@ubbpc.UUCP> <16187@agate.BERKELEY.EDU> <599@quintus.UUCP> <591@tuck.nott-cs.UUCP> <404@ubbpc.UUCP> <7774@aw.sei.cmu.edu> < <594@tuck.nott-cs.UUCP> Sender: news@ux.cs.man.ac.uk Reply-To: chl@r1.UUCP (Charles Lindsey) Organization: University of Manchester, UK Lines: 33 In article <594@tuck.nott-cs.UUCP> anw@maths.nott.ac.uk (Dr A. N. Walker) writes: >[Clay Phipps (>>) and Steven Ryan (>) are surprised that: > >> begin int I := 0, K := 1; > >> ref int Ptr := I; > >> Ptr := K; > >> Print (I); > >> end >prints 0 rather than 1.] Various people have been trying to explain this one. Personally, I would write it as follows. begin loc int I := 0, K := 1; loc ref int Ptr := I; Ptr := K; Print (I); end The keyword 'loc' (which is legal ALGOL 68) serves to introduce a local variable-declaration (as opposed to the identity- (or constant-) declaration which is written int Zero = 0, One = 1; ). You may regard 'loc' as a fancy way of writing 'ref', but with the added side effect that it actually obtains some local space to be 'ref'ed at. So you see at once that the mode (i.e. type) of I is 'ref int', and that Ptr is a variable to hold pointers to 'ref int' variables such as I or K, rather than their contents. Then there should be no surprises. The reason the keyword 'loc' is optional is that it was added at the last moment, the original idea having been to copy the exact syntax of the ALGOL 60 variable-declaration. Personally, I always put it in, and if you leave it out my compiler annoys you with a Warning message.