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

Re: Other rewrites for merge-methods-into-list



    Date: Mon, 25 Jul 88 10:21:03 EST
    From: doug@zaphod.LOCAL (Douglas Rand)

    In a with-slots the variable cannot be the same symbol
    as a slot name.  For example, the following code fails:

    (with-slots (x y) x
      (list x y))

    (with-accessors ((x foo-x) (y foo-y)) x
      (list x y))

Anyone who runs into this problem with with-slots or with-accessors
should make the following changes to their boot.lisp file.  The most
efficient way to make this change is:

1) Make the changes to boot.lisp.
2) Recompile boot.lisp.
3) Put the changes in a seperate file, with (in-package 'pcl) at the
   top.
4) Compile and load that file into your existing image with PCL and your
   code loaded.

This will save you a lot of unecessary recompilation and reloading.

;from boot.lisp

(defmacro with-slots
	  (slots instance &body body &environment env)
  (let ((gensym (gensym)))
    (expand-with-slots (mapcar #'(lambda (ss)
				   (if (symbolp ss) (list ss ss) ss))
			       slots)
		       body
		       env
		       gensym
		       instance
		       #'(lambda (s) `(slot-value ,gensym ',s)))))

(defmacro with-accessors
	  (slot-accessor-pairs instance &body body &environment env)
  (let ((gensym (gensym)))
    (expand-with-slots slot-accessor-pairs
		       body
		       env
		       gensym
		       instance
		       #'(lambda (a) `(,a ,gensym)))))

(defun expand-with-slots (specs body env gensym instance translate-fn)
  `(let ((,gensym ,instance))
     ,@(and (symbolp instance)
	    `((declare (variable-rebinding ,gensym ,instance))))
     ,gensym
     ,@(walk-form body
		  env
		  #'(lambda (f c e)
		      (declare (ignore e))
		      (expand-with-slots-internal specs
						  f
						  c
						  translate-fn)))))
-------