Just Launched: You can now import projects and releases from Google Code onto SourceForge
We are excited to release new functionality to enable a 1-click import from Google Code onto the Allura platform on SourceForge. You can import tickets, wikis, source, releases, and more with a few simple steps. Read More
I've come across the following behaviour and wonder:
(defmacro bag (&body body)
`(let ((*bags* ()))
(declare (type list *bags*)) ; need not be special
(macrolet ((containing (x &optional (name :default))
(format *trace-output* "Expanding(~S)... " name)
(push value (cdr (or (assoc ',name *bags* :test #'eq)
(let ((loc (list ',name)))
(push loc *bags*) loc))))
(format *trace-output* "Stored: ~S~%" *bags*)
'(cdr (assoc :default *bags* :test #'eq))))
> (defun zot(n) (bag (containing n)))
Expanding(:DEFAULT)... Stored: NIL
; Aha, macrolets seem to be expanded at defun-time already.
> (setq *print-length* 6)
> (setq *print-level* 4) ; important, may crash if NIL
> (compile 'zot)
#<SYSTEM::VAR *BAGS* NIL NIL #<SYSTEM::CONST NIL NIL NIL :ALL>
(#<SYSTEM::ANODE SYSTEM::VAR (# NIL NIL) (#)>
#<SYSTEM::ANODE SYSTEM::VAR (# NIL NIL) (#)>)
How comes some system internal state gets into my variable?
(compile 'zot) with *print-level* nil crashes my MS-Windows CLISP (and I thought I
had GC/stack-checks/page overflow detection enabled).
Is this a consequence of CLHS on macrolet: "but the consequences are undefined if the local macro definitions reference any local variable or function bindings that are visible in that lexical environment."?
Is there any hope of getting a variation of this code to work?