Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!njin!princeton!udel!new
From: new@udel.EDU (Darren New)
Newsgroups: comp.lang.misc
Subject: Re: call-by-name
Message-ID: <5821@louie.udel.EDU>
Date: 6 Dec 88 00:40:37 GMT
References: <64961@ti-csl.CSNET>
Sender: usenet@udel.EDU
Reply-To: new@udel.EDU (Darren New)
Organization: University of Delaware
Lines: 53

In article <64961@ti-csl.CSNET> gateley@tilde.UUCP (John Gateley) writes:
>In lisp,
>if foo is supposed to be call by name, you type (foo (lambda () arg) ...)
>instead of (foo arg ...).
>
>This method, however, is not powerful enough to support side-effecting
>call-by-name parameters (without restrictions)
>(define foo (a b)
>  (set! a b))
>(foo c[x] d)
>In this (Scheme) example, if a and b are call-by-name, it is not clear
>what the assignment to a should cause to happen: should it change the
>local value of a, or should it change the (more global) value of c[x].
>Both behaviors are useful, but if changing c[x] is what is desired,
>then something similar to lisp's SETF needs to be used: foo will get passed
>both a function for C[x], and a function which sets C[X].
>
>Someone else said:
>"Call-by-name is not used in any other languages."
>
>It is available in lisp, and any language with first class functions, though
>not under that name, and without the exact syntax.
>
>John Gateley
>gateley@tilde.csc.ti.com

I'm not sure about Scheme, but in LISP, something like the first expression is
actually "call by text". The difference is this:

(foo (lambda () (a[i])) as a call to (define foo (x) (let (i 3) x))
will return a[3] in LISP (if my syntax is right). In Algol-60, the i used
in the called function would be the i in the calling function. i.e.,
function foo (a)
var i : integer;
begin i := 3; return a; end;
function bar()
var i : integer;
    a : array[0..5] of integer;
begin a[3] := 3; a[5] := 5; return foo(a[i]); end;
{Again, forgive the syntax. It's been a while...}

In the Algol-ish example, bar returns 5 (a[5]). In the
LISP-ish version, foo will return a[3]. This is because
LISP is call-by-text (i.e., it is as if the text of the
actual parameter is substituted in for the formal
parameter in the body.)
This is what "function" is for in LISP - it binds the
environment to the argument. I'm not sure whether this
gives call-by-name or not.

                                  - Darren New
                                    Grad CIS student
                                    U. of Delaware