Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!bellcore!texbell!killer!pollux!ti-csl!mips!gateley From: gateley@mips.csc.ti.com (John Gateley) Newsgroups: comp.lang.misc Subject: call-by-name Message-ID: <64961@ti-csl.CSNET> Date: 5 Dec 88 04:00:25 GMT Sender: news@ti-csl.CSNET Reply-To: gateley@tilde.UUCP (John Gateley) Organization: TI Computer Science Center, Dallas Lines: 51 Some misc. commments on Call-by-name parameter passing, in reply to several articles by Mark VandeWettering, Clay Phipps, and others. Mark VandeWettering: > Call by name is very difficult to implement *in languages with > side effects* In functional languages, call by name can be > effectively and efficiently implemented. Call by name is very > popular, and has been refined into "lazy evaluation".... It is not difficult to implement call-by-name in a language which has first class functions (such as lisp or scheme), and if the macro system is good enough, the syntactic sugar can be added too! To define a function which uses "call-by-name", each invocation of the function has to convert each of the arguments to functions of no arguments. 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]. In article <2070@garth.UUCP> phipps@garth.UUCP (Clay Phipps) writes: >The fact that a language feature is enough of a challenge to understanding >that it can be used as the basis of a test question is "evidence" to me >that the feature may be more of a liability than an asset. Complex tools may be used to solve complex problems. Just because, for example, first class procedures are more complex than most languages allow, I would not like to be restricted from using them. A language feature becomes a liability (in my opinion of course) when it can not be applied to problems very well. Call-by-name in the algol-68 language is difficult to use and understand. The usage above (doing call-by-name using functions) is not difficult to use, and applies well to lots of problem. 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