Why when I run the test function does it not reset foo to NIL each
time? Shouldn't the list be one element long each time instead of
growing with every iteration of test? What am I missing?
CL-USER 99 > (defun test ()
(let ((foo '(NIL)))
(push '1 (car foo))))
TEST
CL-USER 100 > (test)
(1)
CL-USER 101 > (test)
(1 1)
CL-USER 102 > (test)
(1 1 1)
CL-USER 103 > (test)
(1 1 1 1)
CL-USER 104 >
Q <······@gmail.com> writes:
> Why when I run the test function does it not reset foo to NIL each
> time? Shouldn't the list be one element long each time instead of
> growing with every iteration of test? What am I missing?
>
> CL-USER 99 > (defun test ()
> (let ((foo '(NIL)))
> (push '1 (car foo))))
> TEST
The other answers are good. Another option: get a more pedantic CL
implementation! Here's what SBCL says:
* (defun test ()
(let ((foo '(NIL)))
(push '1 (car foo))))
; in: LAMBDA NIL
; (PUSH '1 (CAR FOO))
; --> LET*
; ==>
; (SB-KERNEL:%RPLACA #:G1 #:G0)
;
; caught WARNING:
; Destructive function SB-KERNEL:%RPLACA called on constant data.
; See also:
; The ANSI Standard, Special Operator QUOTE
; The ANSI Standard, Section 3.2.2.3
;
; compilation unit finished
; caught 1 WARNING condition
Zach
Zach Beane <····@xach.com> writes:
> Q <······@gmail.com> writes:
>
>> Why when I run the test function does it not reset foo to NIL each
>> time? Shouldn't the list be one element long each time instead of
>> growing with every iteration of test? What am I missing?
>>
>> CL-USER 99 > (defun test ()
>> (let ((foo '(NIL)))
>> (push '1 (car foo))))
>> TEST
>
> The other answers are good. Another option: get a more pedantic CL
> implementation! Here's what SBCL says:
>
> * (defun test ()
> (let ((foo '(NIL)))
> (push '1 (car foo))))
> ; in: LAMBDA NIL
> ; (PUSH '1 (CAR FOO))
> ; --> LET*
> ; ==>
> ; (SB-KERNEL:%RPLACA #:G1 #:G0)
> ;
> ; caught WARNING:
> ; Destructive function SB-KERNEL:%RPLACA called on constant data.
> ; See also:
> ; The ANSI Standard, Special Operator QUOTE
> ; The ANSI Standard, Section 3.2.2.3
> ;
> ; compilation unit finished
> ; caught 1 WARNING condition
>
I have to agree with Zack on this one. When I first started learning CL, I had
similar questions and confusion. Someone suggested switching to SBCL and not
just ignoring warnings, but trying to understand what they meant. I believe
this prevented me from learning some bad habits and it definitely helped in my
understanding of some aspects of the language.
Tim
--
tcross (at) rapttech dot com dot au
In article <························@b58g2000hsg.googlegroups.com>,
Q <······@gmail.com> wrote:
> Why when I run the test function does it not reset foo to NIL each
> time? Shouldn't the list be one element long each time instead of
> growing with every iteration of test? What am I missing?
>
> CL-USER 99 > (defun test ()
> (let ((foo '(NIL)))
> (push '1 (car foo))))
Try (list nil) instead of '(NIL).
The latter is a single inside the function constant
that you modify.
> TEST
>
> CL-USER 100 > (test)
> (1)
>
> CL-USER 101 > (test)
> (1 1)
>
> CL-USER 102 > (test)
> (1 1 1)
>
> CL-USER 103 > (test)
> (1 1 1 1)
>
> CL-USER 104 >
--
http://lispm.dyndns.org
On 18 Apr 2007 08:10:03 -0700, Q <······@gmail.com> wrote:
> Why when I run the test function does it not reset foo to NIL each
> time? Shouldn't the list be one element long each time instead of
> growing with every iteration of test? What am I missing?
>
> CL-USER 99 > (defun test ()
> (let ((foo '(NIL)))
> (push '1 (car foo))))
> TEST
>
> CL-USER 100 > (test)
> (1)
>
> CL-USER 101 > (test)
> (1 1)
>
> CL-USER 102 > (test)
> (1 1 1)
>
> CL-USER 103 > (test)
> (1 1 1 1)
http://www.cs.cmu.edu/Groups/AI/html/faqs/lang/lisp/part3/faq-doc-14.html
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")