From: Matthew D Swank
Subject: setf and push behave differently with symbol macro
Date: 
Message-ID: <1128583743.689990.181010@f14g2000cwb.googlegroups.com>
(defmacro defglobal (name &optional value)
  (let ((internal (gensym)))
    `(progn
       (defparameter ,internal ,value)
       (define-symbol-macro ,name ,internal))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;on sbcl
CL-USER> (defglobal glob)
GLOB
CL-USER> glob
NIL
CL-USER> (let ((glob 4)) glob)
4
CL-USER> glob
NIL
CL-USER> (let ((glob '()))
           (setf glob (cons 'foo glob)) glob)
(FOO)
CL-USER> glob
NIL
CL-USER> (let ((glob '()))
           (push 'foo glob) glob)
NIL
CL-USER> glob
(FOO)
CL-USER>

why?

Matt
--
"You do not really understand something unless you can
 explain it to your grandmother." - Albert Einstein.

From: Pascal Costanza
Subject: Re: setf and push behave differently with symbol macro
Date: 
Message-ID: <3qk3soFf406eU1@individual.net>
Matthew D Swank wrote:
> (defmacro defglobal (name &optional value)
>   (let ((internal (gensym)))
>     `(progn
>        (defparameter ,internal ,value)
>        (define-symbol-macro ,name ,internal))))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;on sbcl
> CL-USER> (defglobal glob)
> GLOB
> CL-USER> glob
> NIL
> CL-USER> (let ((glob 4)) glob)
> 4
> CL-USER> glob
> NIL
> CL-USER> (let ((glob '()))
>            (setf glob (cons 'foo glob)) glob)
> (FOO)
> CL-USER> glob
> NIL
> CL-USER> (let ((glob '()))
>            (push 'foo glob) glob)
> NIL
> CL-USER> glob
> (FOO)
> CL-USER>
> 
> why?

looks like a bug in SBCL.

Pascal

-- 
OOPSLA'05 tutorial on generic functions & the CLOS Metaobject Protocol
++++ see http://p-cos.net/oopsla05-tutorial.html for more details ++++
From: Alan Crowe
Subject: Re: setf and push behave differently with symbol macro
Date: 
Message-ID: <8664sbndym.fsf@cawtech.freeserve.co.uk>
Matthew D Swank reports that his global lexical is not
being shadowed in an inner scope when used as the
destination of a push:

     (defmacro defglobal (name &optional value)
       (let ((internal (gensym)))
	 `(progn
	    (defparameter ,internal ,value)
	    (define-symbol-macro ,name ,internal))))

     (let ((glob '()))
       (push 'foo glob) glob) => NIL

     glob => (foo)

I've written a test script

    (defmacro defglobal (name &optional value)
      (let ((internal (gensym)))
	`(progn
	   (defparameter ,internal ,value)
	   (define-symbol-macro ,name ,internal))))

    (defglobal glob)

    (format t "~&~A" (lisp-implementation-type))

    (format t "~&Local definition ~A."
	    (let ((glob '()))
	      (push 'foo glob) glob))

    (format t "~&Global definition ~A." glob)

and get the results

CLISP
Local definition (FOO).
Global definition NIL.

International Allegro CL Trial Edition
Local definition (FOO).
Global definition NIL.

CMU Common Lisp
Local definition (FOO).
Global definition NIL.

All three are shadowing as expected.

Alan Crowe
Edinburgh
Scotland
From: Christophe Rhodes
Subject: Re: setf and push behave differently with symbol macro
Date: 
Message-ID: <sqd5mi4wmq.fsf@cam.ac.uk>
Alan Crowe <····@cawtech.freeserve.co.uk> writes:

> Matthew D Swank reports that his global lexical is not
> being shadowed in an inner scope when used as the
> destination of a push:
> and get the results
>
> CMU Common Lisp
> Local definition (FOO).
> Global definition NIL.
>
> All three are shadowing as expected.

Well, that's odd, because running the code at the CMUCL repl reveals
that it suffers the same symptom as SBCL.  How did you run your
script?

In any case, the bug in SBCL is fixed, I believe, by the patch below,
which will probably make it into the public CVS shortly.

Christophe

Index: src/code/macroexpand.lisp
===================================================================
RCS file: /cvsroot/sbcl/sbcl/src/code/macroexpand.lisp,v
retrieving revision 1.8
diff -u -r1.8 macroexpand.lisp
--- src/code/macroexpand.lisp   14 Jul 2005 16:30:36 -0000      1.8
+++ src/code/macroexpand.lisp   6 Oct 2005 13:11:45 -0000
@@ -58,6 +58,8 @@
            (cond ((and (consp local-def)
                        (eq (car local-def) 'macro))
                   (values (cdr local-def) t))
+                 (local-def
+                  (values form nil))
                  ((eq (info :variable :kind form) :macro)
                   (values (info :variable :macro-expansion form) t))
                  (t
From: Alan Crowe
Subject: Re: setf and push behave differently with symbol macro
Date: 
Message-ID: <864q7uhbv9.fsf@cawtech.freeserve.co.uk>
Christophe Rhodes:
> > CMU Common Lisp
> > Local definition (FOO).
> > Global definition NIL.
> >
> > All three are shadowing as expected.
>
> Well, that's odd, because running the code at the CMUCL repl reveals
> that it suffers the same symptom as SBCL.  How did you run your
> script?

You are right, it is broken in CMUCL 19a.

It is a regression. It worked for me on an old machine
running 18d.

Alan Crowe
Edinburgh
Scotland
From: Rob Warnock
Subject: Re: setf and push behave differently with symbol macro
Date: 
Message-ID: <Ge-dnX-e9pX9w9veRVn-qg@speakeasy.net>
Alan Crowe  <····@cawtech.freeserve.co.uk> wrote:
+---------------
| You are right, it is broken in CMUCL 19a.
| It is a regression. It worked for me on an old machine running 18d.
+---------------

It's broken in 18e as well. I get the same results whether it's
compiled or not.


-Rob

p.s. Heh! I just dug out something I wrote way back on 17 Feb 2004
(Message-ID: <······················@speakeasy.net>):

    ... but lately I've been having some problems with my DEFLEX macro
    in CMUCL. I need to investigate a bit further, but it looks like
    the symbol macro isn't being properly shadowed in some cases by a
    subsequent lexical binding. [The problem seems to arise when the
    inner lexical variable is used by a SETF-expander such as INCF.]

I wonder if the "lately" above corresponds to when I switched from
18d to 18e?!?  ;-}

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607