Re: lambda-returning defmacro, capture



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
.



Relevant Pages

  • Re: defvar affecting captured closure variables ?
    ... There are three kinds of variables: lexical variables, dynamic variables, ... so you are therefore outside the realm of the spec. ... global lexicals, no problem will result. ... Your program is in error so the standard does not apply here. ...
    (comp.lang.lisp)
  • Re: lambda-returning defmacro, capture
    ... The standard specifies ... none of which VARR fits. ... So really, if you want "global lexicals", you need to use ... Inside a lexical scope, we can clearly access either the lexical ...
    (comp.lang.lisp)
  • Re: Ron Garret considered harmful [Re: DEFSTRUCT and lexical environment]
    ... some of your responses concerned simple disagreements. ... | disagreement is a misrepresentation. ... | is required by the standard to return 2 and not 1. ... CL does have global lexicals. ...
    (comp.lang.lisp)
  • Re: Scheme macros
    ... > seen from the definition of FOO. ... > to in macros to refer to ... but rather the lack in CL of global lexicals. ... (defmacro foo () ...
    (comp.lang.lisp)
  • Re: defvar affecting captured closure variables ?
    ... ignore the advice about global lexicals. ... | bind these globals, since otherwise you'll get a lexical foo when you ... | bind foo. ... It is a symbol macro with expansion: ...
    (comp.lang.lisp)