Quote:
Originally Posted by zaxonus
I am using Common Lisp and I wonder how I can pass parameters by address to a Lisp function.
|
While there are ways of modifying parameters in Lisp, destructive modification is usually the wrong way to program in the language. If your aim is simply to have more than one return value, then combine the return values together as a list.
There is a sense in which lists are already passed by reference. For example, the following will change the first element of the list:
Code:
(defun modify (n) (setf (car n) 18))
You can change a dynamically scoped variable by passing it in as a quoted from:
Code:
(defun modify (n) (set n 18))
(setf x 2)
(modify 'x)
Or you could make use of a lambda function to allow another function to modify outside values:
Code:
(defun modify (setn) (funcall setn 18))
(modify (lambda (y) (setq x y)))
But chances are that a reframing of the problem will make these unnecessary.