Re: lambda-returning defmacro, capture
- From: Juho Snellman <jsnell@xxxxxx>
- Date: 13 Dec 2006 19:26:15 GMT
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.
--
Juho Snellman
.
- Follow-Ups:
- Re: lambda-returning defmacro, capture
- From: Alex Mizrahi
- Re: lambda-returning defmacro, capture
- From: Pascal Bourguignon
- Re: lambda-returning defmacro, capture
- References:
- Re: lambda-returning defmacro, capture
- From: Andreas Thiele
- Re: lambda-returning defmacro, capture
- From: Pascal Bourguignon
- Re: lambda-returning defmacro, capture
- From: Alex Mizrahi
- Re: lambda-returning defmacro, capture
- Prev by Date: Re: merits of Lisp vs Python
- Next by Date: Re: merits of Lisp vs Python
- Previous by thread: Re: lambda-returning defmacro, capture
- Next by thread: Re: lambda-returning defmacro, capture
- Index(es):
Relevant Pages
|