Subject: Re: newbie: does lisp copy all arguments? From: Erik Naggum <email@example.com> Date: Sun, 10 Feb 2002 17:05:03 GMT Newsgroups: comp.lang.lisp Message-ID: <firstname.lastname@example.org> * Christopher Browne <email@example.com> | By and large, Lisp does "call by reference," which means that what | would be passed to the function is a _reference_ to the board. This is slightly misleading. The usual terminology is "call by value", "call by name", and "call by reference", which refer to how the arguments in the function call are passed to the function. 1 A call by value means that the value yielded by the argument is passed to the function. This means that the expression is fully computed and only the value is passed along to the function with no trace of its origins. 2 A call by name means that the expression in the function call is passed to the function, such that the called function evaluates it itself. 3 A call by reference means that a place that holds the value of the argument is passed to the function. Typically, the variable that holds the value is passed to the function so the function can write back into the variable. All Lisps are strict call-by-value languages. Macros are in a sense call-by-name "functions". But in no sense does Lisp offer a call by reference concept. Other languages have different semantics. E.g., Ada has the very elegant in/out parameter specification: in parameters are call-by-value, out are _effectively_, but need not actually be, call-by-name or -reference. Fortran is generally call-by-reference. C++ is usually call-by-value, but you may request call-by-reference. Whether you pass a pointer to an object or the object itself is entirely orthogonal to the call-by-value or call-by-reference issue. Common Lisp offers object identity as one of its basic features as well as the ability to store any kind of object in a Lisp "storage cell" location, meaning a variable, structure or class slot, array cell, the car and cdr of a cons, etc, etc. This naturally means that Lisp must pass around some kind of references to objects, as no other mechanism can store any kind of value in equal amounts of space. However, this does not mean that Common Lisp provides the kind of pointers that C/C++ offers, although some Lisps have provided "locatives" which refer to sub-elements of structured objects, like an individual array cell, class or structure slot, and the like. They would still be passed by value, however. /// -- In a fight against something, the fight has value, victory has none. In a fight for something, the fight is a loss, victory merely relief.