From: Tunc Simsek
Subject: WITH-SLOTS
Date: 
Message-ID: <395BB030.F9D375F3@robotics.eecs.berkeley.edu>
Regards,

I hope someone can help me with this:

USER[34]: (macroexpand-1 '(with-slots (x y) o (setq x y)))

(LET ((#:G1550 O))
  (DECLARE (IGNORABLE #:G1550))
  (DECLARE (PCL::VARIABLE-REBINDING #:G1550 O))
  #:G1550
  (SYMBOL-MACROLET ((X (SLOT-VALUE #:G1550 'X)) (Y (SLOT-VALUE #:G1550
'Y)))
    (SETQ X Y)))

I have impelemented WITH-ACCESS that mimics WITH-SLOTS:

SHIFT[35]: (macroexpand-1 '(with-access (x y) o (setq x y)))

(LET ((#:G1555 O))
  (DECLARE (IGNORABLE #:G1555))
  (DECLARE (PCL::VARIABLE-REBINDING #:G1555 O))
  #:G1555
  (SYMBOL-MACROLET ((X (SLOT-ACCESS GENSYM 'X)) (Y (SLOT-ACCESS GENSYM
'Y)))
    (SETQ X Y)))

My question is, how is SYMBOL-MACROLET and VARIABLE-REBINDING used here,
does anyone
have any better implementations?  I'm sure this will work, until
something goes wrong,
at which point there'll be a real mess.

Besides, will (SETQ X Y) do the right thing?

Thanks,
Tunc

p.s. my implementation is:

(defmacro with-access (args obj &rest code)
  (let ((gensym (gensym)))
    `(let ((,gensym ,obj))
       (declare (ignorable ,gensym))
       (declare (pcl::variable-rebinding ,gensym ,obj))
       ,gensym
       (symbol-macrolet (,@(mapcar #'(lambda (arg)
				       `(,arg (slot-access gensym ',arg))) args))
	 ,@code))))

From: Tim Moore
Subject: Re: WITH-SLOTS
Date: 
Message-ID: <8jgkcb$9nh$0@216.39.145.192>
On Thu, 29 Jun 2000, Tunc Simsek wrote:

> I have impelemented WITH-ACCESS that mimics WITH-SLOTS:
> 
> SHIFT[35]: (macroexpand-1 '(with-access (x y) o (setq x y)))
> 
> (LET ((#:G1555 O))
>   (DECLARE (IGNORABLE #:G1555))
>   (DECLARE (PCL::VARIABLE-REBINDING #:G1555 O))
>   #:G1555
>   (SYMBOL-MACROLET ((X (SLOT-ACCESS GENSYM 'X)) (Y (SLOT-ACCESS GENSYM
                                      ^^^^^^                      ^^^^^^
You've got a bug in there.
> 'Y)))
>     (SETQ X Y)))
> 

> My question is, how is SYMBOL-MACROLET and VARIABLE-REBINDING used here,
> does anyone
> have any better implementations?  I'm sure this will work, until

symbol-macrolet does what it sounds like: it provides a macroexpanded form
for a variable.  x gets replaced with (slot-access #:G1555 'x).

VARIABLE-REBINDING is an internal PCL thing.  You almost certainly don't
want to use it in your code.

> something goes wrong,
> at which point there'll be a real mess.

This should be fairly robust.  symbol-macrolet was introduced into the
language to enable just this kind of macro.

> Besides, will (SETQ X Y) do the right thing?

Yes, if you've defined #'(setf slot-access) or some other setf method for
slot-access.
> p.s. my implementation is:
> 
> (defmacro with-access (args obj &rest code)
>   (let ((gensym (gensym)))
>     `(let ((,gensym ,obj))
>        (declare (ignorable ,gensym))
>        (declare (pcl::variable-rebinding ,gensym ,obj))
>        ,gensym
>        (symbol-macrolet (,@(mapcar #'(lambda (arg)
> 				       `(,arg (slot-access gensym ',arg))) args))
> 	 ,@code))))
> 

You're missing a comma :)

Tim
From: Tunc Simsek
Subject: Re: WITH-SLOTS
Date: 
Message-ID: <Pine.SOL.4.10.10006292115220.11619-100000@tudor.EECS.Berkeley.EDU>
On 29 Jun 2000, Tim Moore wrote:

> On Thu, 29 Jun 2000, Tunc Simsek wrote:
> 
> > I have impelemented WITH-ACCESS that mimics WITH-SLOTS:
> > 
> > SHIFT[35]: (macroexpand-1 '(with-access (x y) o (setq x y)))
> > 
> > (LET ((#:G1555 O))
> >   (DECLARE (IGNORABLE #:G1555))
> >   (DECLARE (PCL::VARIABLE-REBINDING #:G1555 O))
> >   #:G1555
> >   (SYMBOL-MACROLET ((X (SLOT-ACCESS GENSYM 'X)) (Y (SLOT-ACCESS GENSYM
>                                       ^^^^^^                      ^^^^^^
> You've got a bug in there.
> > 'Y)))
> >     (SETQ X Y)))
> > 
> 
> > My question is, how is SYMBOL-MACROLET and VARIABLE-REBINDING used here,
> > does anyone
> > have any better implementations?  I'm sure this will work, until
> 
> symbol-macrolet does what it sounds like: it provides a macroexpanded form
> for a variable.  x gets replaced with (slot-access #:G1555 'x).
> 
> VARIABLE-REBINDING is an internal PCL thing.  You almost certainly don't
> want to use it in your code.

Yes, but is it necessary in this example?  If so, what is the alternative?

Thanks,
Tunc

> 
> > something goes wrong,
> > at which point there'll be a real mess.
> 
> This should be fairly robust.  symbol-macrolet was introduced into the
> language to enable just this kind of macro.
> 
> > Besides, will (SETQ X Y) do the right thing?
> 
> Yes, if you've defined #'(setf slot-access) or some other setf method for
> slot-access.
> > p.s. my implementation is:
> > 
> > (defmacro with-access (args obj &rest code)
> >   (let ((gensym (gensym)))
> >     `(let ((,gensym ,obj))
> >        (declare (ignorable ,gensym))
> >        (declare (pcl::variable-rebinding ,gensym ,obj))
> >        ,gensym
> >        (symbol-macrolet (,@(mapcar #'(lambda (arg)
> > 				       `(,arg (slot-access gensym ',arg))) args))
> > 	 ,@code))))
> > 
> 
> You're missing a comma :)
> 
> Tim
> 
> 
> 
> 
From: Tim Moore
Subject: Re: WITH-SLOTS
Date: 
Message-ID: <8jhd2g$2n3$0@216.39.145.192>
On Thu, 29 Jun 2000, Tunc Simsek wrote:
> 
> On 29 Jun 2000, Tim Moore wrote:
> 
> > On Thu, 29 Jun 2000, Tunc Simsek wrote:
> > > (LET ((#:G1555 O))
> > >   (DECLARE (IGNORABLE #:G1555))
> > >   (DECLARE (PCL::VARIABLE-REBINDING #:G1555 O))
> > >   #:G1555
> > >   (SYMBOL-MACROLET ((X (SLOT-ACCESS GENSYM 'X)) (Y (SLOT-ACCESS GENSYM
> >                                       ^^^^^^                      ^^^^^^
> > You've got a bug in there.
> > > 'Y)))
> > >     (SETQ X Y)))
> > VARIABLE-REBINDING is an internal PCL thing.  You almost certainly don't
> > want to use it in your code.
> 
> Yes, but is it necessary in this example?  If so, what is the alternative?

No it's not.  You don't need declarations to rebind variables in Lisp :)
Just leave it out.

I'm not an expert in the PCL internals, but at first glance it looks like
pcl::variable-rebinding is used by the PCL codewalker to do some funky
optimization.  Look at the PCL sources if you really care.

Tim