Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!mcnc!rti-sel!dg_rtp!throopw From: throopw@dg_rtp.UUCP (Wayne Throop) Newsgroups: net.lang.c Subject: swap by name Message-ID: <431@dg_rtp.UUCP> Date: Thu, 3-Jul-86 16:55:27 EDT Article-I.D.: dg_rtp.431 Posted: Thu Jul 3 16:55:27 1986 Date-Received: Fri, 4-Jul-86 04:47:03 EDT References: <1201@brl-smoke.ARPA> <193@stracs.cs.strath.ac.uk> <733@ho95e.UUCP> <1836@brl-smoke.ARPA> Lines: 30 > gwyn@brl-smoke.UUCP (Doug Gwyn (VLD/VMB) ) > It may be amusing and/or instructive to contemplate the fact that > there is no way to write a function that exchanges the contents of > two variables in a language where parameters are passed "by name". Amusing, instructive.... and wrong. I am assuming that you mean "Given a language which passes arguments to functions with call-by-name semantics, it is impossible write an 'exchange argument pair' function, no matter what other facilities the language provides". This is clearly incorrect. In fact, the C language is a counterexample (assuming that the C language includes the preprocessor). Consider: macros act much like functions with by-name arguments. The trick is to utter the swap while mentioning the arguments only once. Thus, one needs a bind-by-reference operation, which in C is nicely provided by the '&' operator (with some restrictions, granted). My conclusion: a swap function is easy to implement even with pass-by-name functions, *provided* there is a bind-by-reference operator in the language. -- It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a long time to say, and to listen to. --- J. R. R. Tolkien -- Wayne Throop !mcnc!rti-sel!dg_rtp!throopw