Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!news.kei.com!wang!news
From: ian@mdsun1.technion.ac.il (Ian Underwood)
Subject: Baffled by GCL: (setf *special-variable*) ignored...  why? 
Organization: Technion
Date: Sun, 6 Nov 1994 14:30:01 GMT
Message-ID: <CyuoA2.LAq@discus.technion.ac.il>
Sender: news@wang.com
Lines: 72


I'm having a problem with GCL, or perhaps just with Lisp.  
Consider the following definitions:

  test.lisp:

    (defvar *global-var* nil)


    (defun test-clear ()
      (setf *global-var* '((:a ()))))


    (defun test-more (value)
      (push value (second (assoc :a *global-var*))))


    (defun test-list (l)
      (test-clear)
      (loop for x in l
        do (test-more x))
      (pprint *global-var*))


Here is how it behaves under GCL 1.0 (compiled using GCC 2.5.8), 
running on a Sparc 10 under Solaris 2.3:

  > (load "test.lisp")
  Loading test.lisp
  Finished loading test.lisp
  T

  > (test-list '(a b c))
  ((:A (C B A)))				;;  So far, so good. 

  > (test-list '(d e f))
  ((:A (F E D C B A)))                                    	;;  Should be  ((:A (F E D))  
					;;  (*global-var* should have been re-initialized)

  > (test-clear)
  ((:A (F E D C B A)))                   		;;  Should be ((:A NIL))

  > (setf *global-var* '((:a ())))) 		;;  This is what test-clear does.
  ((:A NIL))

  > *global-var*
  ((:A NIL))         				;;  Seems to have worked, but...

  > (test-list '(x y z))
  ((:A (Z Y X F E D C B A)))			;;  apparently not!  
					;;  The old value seems to have persisted. 

  >(load "test.lisp")
  Loading test.lisp
  Finished loading test.lisp
  T
 
  >*global-var*
  ((:A (Z Y X F E D C B A)))			;;  As expected, variable value not reset, but...
 
  >(test-list '(u v w))
  ((:A (W V U)))				;;  now test-clear seems to work!  

  >(test-list '(d e f))			
  ((:A (F E D W V U)))			;;  But only the first time. 


This makes no sense to me at all.   Is this a bug in GCL, or is there something about
special variables that I don't understand?

-Ian

