Swap by name

Chris Torek chris at maryland.ARPA
Sat Jul 5 10:47:52 AEST 1986


	From: Root Boy Jim <rbj at icst-cmr.arpa>

	> I merely chose a poor example.  Call by reference and call
	> by name often have identical effects.  [me]

	That doesn't mean they are the same.  [rbj]

That was my point.  They are not the same, except in a particular
set of cases.  That is why (and when) it is important to know what
methods of parameter passing are legal in whatever language you
are using.

	I would dispute that no one uses call by name. Consider
	that in APL you can pass a character string and execute it
	to get the result. I suppose I am splitting hairs, but the
	effect is the same. I imagine one could do the same thing
	in LISP, or any interpretive language.

Actually, this is a good point.  In Lisp, a fexpr is in fact a
sort of call-by-name, though depending on your scope rules it
may do something very unexpected: evaluating `v' in the callee
may provide the callee's `v', rather than the caller's.  This
is a particularly nasty problem in Gosling Emacs MLisp, where
all MLisp `arguments' are in fact fexpr's.

However, I stand by my statement, at least with a little modification:
no one wants to be forced to use call by name exclusively.  (Not
that other methods are not available in Algol.)  And I understand
taht Common Lisp does not have fexpr's.

	~> call by value-result

	I was thinking of the caller squirrelling away the value
	in a temporary location, passing it by reference (thus
	allowing modification by the callee) and then copying the
	result to the real variable.

That works too---which just goes to show that there is more than
one way to skin a function.

`A swap, by any call by name, would smell as sweet ....'
`You can call me Ref, or you can call me Val, ....'
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list