Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!lll-crg!caip!brl-adm!brl-smoke!smoke!rbj@icst-cmr.ARPA From: rbj@icst-cmr.ARPA (Root Boy Jim) Newsgroups: net.lang.c Subject: Swap by name Message-ID: <1937@brl-smoke.ARPA> Date: Thu, 3-Jul-86 13:25:17 EDT Article-I.D.: brl-smok.1937 Posted: Thu Jul 3 13:25:17 1986 Date-Received: Sat, 5-Jul-86 05:54:18 EDT Sender: news@brl-smoke.ARPA Lines: 53 In article <1836@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >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". How so? It seems rather simple. I have here a C program that effects call-by-name and does indeed perform a swap: [Example using `thunks' deleted] Yow! Are we talking about the same thing yet? I seem to remember three types (possibly four) of parameter passing: 1) Call by value C scalars 2) Call by reference C pointers, arrays, Fortran variables 3) Call by name Algol call by name (it also does val & ref) Call by reference went something like this: the calling routine would pass the string representation of the argument and the caller would parse it to figure out the argument. Thus if we had a declaration and call: (I forgot Algol so I'm bastardizing C) int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int i = 5; main() { snafu(a[i]); } snafu(bar) call_by_name bar; { printf("%d\n",bar); /* prints 5 */ i = 7; printf("%d\n",bar); /* prints 7 */ } At least that's what Dr. Vic the BASILIsk told me. Now it does seem that Chris's thunktions will provide a similar effect, so forgive me if this whole article is unnecessary. However, while I could write a thunktion similar to snafu to return the address of any single array element, call by name would allow me to pass a multidimensioned array reference to the same function as well and muck with it. I have never understood the motivation for this technique, or if I ever did, I probably didn't like it. Can you say interpreter? The fourth method I have heard is `Call by value-result'. It seems to be a variation on call by reference or value depending on how it is done. (Root Boy) Jim Cottrell RHAPSODY in Glue!