Subject: Re: lambda-returning defmacro, capture
From: (Rob Warnock)
Date: Wed, 13 Dec 2006 06:47:00 -0600
Newsgroups: comp.lang.lisp
Message-ID: <>
<> wrote:
| What's the correct way to define a global without getting
| dynamic scope, or SBCL warnings?

While you can perhaps turn off the warning [I think both SBCL
and CMUCL have some variable (not the same name?) you can set
that will suppress it], don't count on being able to turn off
the dynamic scope. In ANSI Common Lisp *all* global variables
are special, that is, have dynamic scope.

But you can fake it. Google for articles about using CL's
DEFINE-SYMBOL-MACRO (usually inside a macro called DEFLEXICAL
or DEFLEX) to define "global lexical variables" which can
then be shadowed by lexical bindings. Here's the simplest
version of it I've seen so far:

    > (defmacro deflex (var val &optional (doc nil docp))    
	(let ((backing-var (make-symbol (symbol-name var))))
	     (defparameter ,backing-var ,val ,doc)
	     ,@(when docp `((setf (documentation ',var 'variable) ,doc)))
	     (define-symbol-macro ,var ,backing-var))))

    > (deflex foo 13)

    > (defun foo () foo)

    > (let ((foo 234))
	(list foo (foo)))

    (234 13)

Is that what you're looking for?


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607