🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #604

Re: swap(x,y) in Algol 60

#604
From: Dik T. Winter
Date: Fri, 01 Sep 1989 22:48
30 lines
1491 bytes
In article <31690@cornell.UUCP> bard@cs.cornell.edu (Bard Bloom) writes:
 > I have seen a folk theorem that it is impossible to define swap(x,y) in
 > Algol, where swap is supposed to be a procedure with two call-by-name integer
 > arguments which exchanges their values.  It's not exactly clear what the
 > statement of the theorem should be when (say) x and y have side effects.
 > 
Define:
	"procedure" swap(x) with:(y);
	"begin"
	    "integer" z;
	    z:= x; x:= y; y:= z;
	"end" swap;

Perfectly legal, and it works if x and y have no side effects.
But if an argument has side effects, there is a problem:
	"integer" i, j;
	"integer" "array" x[10], y[10];
	"integer" "procedure" indexi;
	"begin" indexi := i; i := i + 1 "end";
	"integer" "procedure" indexj;
	"begin" indexj := j; j := j + 1 "end:;
	i := 1; j := 1;
	swap(x[indexi], y[indexj]);
will not swap x[1] and y[1], but y[1] will be stored in x[2] and
x[1] will be stored in y[2], and there is no possible rewrite of swap
that corrects this.
-- 
dik t. winter, cwi, amsterdam, nederland
INTERNET   : dik@cwi.nl
BITNET/EARN: dik@mcvax
Technical Details
Message-ID: <8369@boring.cwi.nl>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!cs.utexas.edu!uunet!mcsun!mcvax!dik
References: <31690@cornell.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!cs.utexas.edu!uunet!mcsun!mcvax!dik
From: dik@cwi.nl (Dik T. Winter)
Newsgroups: comp.lang.misc
Subject: Re: swap(x,y) in Algol 60
Keywords: swap, algol
Message-ID: <8369@boring.cwi.nl>
Date: 1 Sep 89 22:48:42 GMT
References: <31690@cornell.UUCP>
Organization: CWI, Amsterdam
Lines: 30