From: David Neves
Subject: Re: mutating params passed by ref
Date: 
Message-ID: <neves-1210951710130001@neves.ils.nwu.edu>
In article <··········@agate.berkeley.edu>,
·······@trombone.CS.Berkeley.EDU (Kevin Murphy) wrote:

:  I want to be able to write
:  
:  (defun foo (kb)
:     (push '1 kb))
:  
:  and have the kb argument changed in the caller's environment.
:  However, this doesn't happen, even though push is a destructive
function, and - at
:  least according to the Franz lisp manual - lists are passed by reference.
That is not quite right.  Lisp is a pass-by-value language however since
it is passing pointers around most of the time it seems as though you are
passing by reference.

Function FOO was passed a pointer to the start of a list.  If you really
want to change the front of the list in the caller's environment you would
have to use a dummy/sentinel item to mark the front of the list and then
destructive list operations.
e.g.
(setq mylist '(dummy a b c))
(foo mylist)
value of mylist is now: (dummy 1 a b c)

(defmacro push-dummy-list (item var)
  `(progn
     (setf (rest ,var) (cons ,item (rest ,var)))
     ,var))

(defun foo (kb)
   (push-dummy-list 1 kb))