Re: Beginners Question - Can't manipulate a local variable
Posted: Mon Jan 04, 2010 9:36 pm
Code: Select all
(defun add-to-list (l) (setf l ...))
Code: Select all
void f1(int x) { x=5; }
void f2(List l) { l=new List(); }
Code: Select all
;; Good: have add-to-list return the modified list; the caller can change its variable if desired
(setf l (add-to-list l))
;; Bad: have add-to-list modify the list
(defun add-to-list (l)
(when l
(setf (car l) 1
(cdr l) 2))
l)
Code: Select all
List addToList(List l)
{
if(!l.null())
{
l.car=1;
l.cdr=2;
}
return l;
}