[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: quote doesn't produce a fresh object

From: Kevin Rodgers
Subject: Re: quote doesn't produce a fresh object
Date: Tue, 08 Jun 2004 11:12:53 -0600
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv: Gecko/20020406 Netscape6/6.2.2

Don Bashford wrote:
> (defun myfun (x)
>   (let ((xs '(nil)))
>     (print xs)
>     (setcar xs "foo"))
>   t)
> On first invocation, (myfun 'arg) prints (nil) and returns t, as
> expected.  But on second invocation, it prints ("foo").  It seems in the
> second invocation, the let variable xs gets the old object from the
> previous invocation.  If '(nil) is changed to (list nil) in myfun, the
> problem does not occur, so the problem is with quote, not with let.

That is not a bug. 'FORM is equivalent to (quote FORM) and is used to
denote a constant Lisp object, so the xs symbol should reference the
original object (which is cons'ed when the defun form is read, not when
it is evaluated).

Kevin Rodgers

reply via email to

[Prev in Thread] Current Thread [Next in Thread]