Subject: Re: unbound variable in macro
From: (Rob Warnock)
Date: 1999/09/29
Newsgroups: comp.lang.lisp
Message-ID: <7ss4th$>
Coby  <> wrote:
| I am trying to write a little macro for debugging purposes.  It is
| intended to capture local variable values to a global.  I would like to
| use it as below:
| (defun blah ()
|   (let ((x 11) (y 22))
|      (trap-let-list '((x 11) (y 22)) *foo*))
|      (...function code...)))
| The idea being i could insert it in a function, copy and paste the let
| list, redefine the function and next time it ran capture the data
| values to the global of my choice.
| I tried:
| (defmacro trap-let-list (let-list global)
|    `(setf ,global (mapcar #, (mapcar #'car ,let-list))))
| among many other straw-grasping things.  I can not escape the "attempt
| to evaluate the unbound variable 'x'" abortion, or ending up with *foo*
| being (x y) and not (11 22).

You're pretty close, actually. First, since TRAP-LET-LIST is a macro,
you don't need to (in fact, mustn't!) quote the "let-list" arg. Second,
I don't know what you meant by that "#," in the first MAPCAR, but the
following way of setting the result works:

	> (defvar *foo*)
	> (defmacro trap-let-list (let-list global)
	   `(setf ,global (list ,@(mapcar #'car let-list))))
	> (defun blah ()
	    (let ((x 11) (y 22))
	      (incf x 7)	; simulate something happening...
	      (incf y)		; ditto
	      (trap-let-list ((x 11) (y 22)) *foo*))  ; now take snapshot
	> (blah)
	> *foo*
	(18 23)

'Zat what you were looking for?


Rob Warnock, 8L-846
Applied Networking
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		FAX: 650-933-0511
Mountain View, CA  94043	PP-ASEL-IA