Re: lambda-returning defmacro, capture



Juho Snellman <jsnell@xxxxxx> writes:

Alex Mizrahi <udodenko@xxxxxxxxxxxxxxxxxxxxx> wrote:
(message (Hello 'Pascal)
(you :wrote :on '(Wed, 13 Dec 2006 14:15:50 +0100))
(

PB> Well, that's the point: there is no _standard_ way to define a global
PB> non-dynamic variable.

PB> So, it seems that both sbcl and clisp allow defining global "lexical"
PB> variables with SETF/SETQ. But this is no standard Common Lisp.

i wonder what's wrong with this:

CG-USER(1): (setf (symbol-value 'varr) 10)
10
CG-USER(2): (funcall (let ((varr 11)) (lambda () varr)))
11
CG-USER(3): varr
10

ain't that "global non-dynamic variable"?

No, it is undefined behaviour. The standard specifies (in 3.1.2.1.1)
three kinds of variables, none of which VARR fits. The standard also
doesn't specify what should be done for non-variables that are used
syntactically like variables.

It happens that all implementations I know of have chosen the same
behaviour for this, and interpret VARR as referring to the value slot
of the symbol (though sometimes with warnings of an undefined variable
being used). Thus the following code will print 11, even though FOO
hasn't been declared special either globally or in the lexical scope
of BAR.

(setf (symbol-value 'foo) 10)

(defun bar ()
foo)

(let ((foo 11))
(declare (special foo))
(print (bar)))

So really, if you want "global lexicals", you need to use
symbol-macros.

Well, right, but (setf (symbol-value 'sym) val) and (symbol-value 'sym)
seem to be defined independently of the different kind of variable.

So you're right that using sym to access (symbol-value 'sym) in the
case of a non dynamic variable is not specified, but we can use
symbol-value.


(setf (symbol-value 'varr) 10)

Inside a lexical scope, we can clearly access either the lexical
variable, or the symbol value:

(funcall (let ((varr 11)) (lambda () (symbol-value 'varr))))
--> 10
(funcall (let ((varr 11)) (lambda () varr)))
--> 11

In the global scope, we can only legally access the symbol value:

(symbol-value 'varr)
--> 10



varr ; is undefined apparently.

But:

(boundp 'varr)
--> T



By the way, I don't find a clear specification that SYMBOL-VALUE
should access the value of dynamic variables... There's some weak
correlation of the two thru boundp, but that's all I can find.

--
__Pascal Bourguignon__ http://www.informatimago.com/

PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.
.