Re: setq givs a warning i SBCL, Not CLISP

Pascal Costanza <pc@xxxxxxxxx> writes:

I wonder whether the following would be good enough:

(define-symbol-macro var (symbol-value 'var))

...or as a higher-order macro:

(defmacro defglobal (name expression)
(define-symbol-macro ,name (symbol-value ',name))
(setf (symbol-value ',name) ,expression)


Not quite: this approach doesn't prevent somebody from accidentally
dynamically rebinding the variable named NAME, which wouldn't be
possible if the variable were really lexical. Consider things without
the symbol-macro:

(defun some-function () (symbol-value 'some-symbol))
(setf (symbol-value 'some-symbol) 100)
(let ((some-symbol 10))
(declare (special some-symbol))

Putting the value on the symbol's plist would do slightly better, but
would be prone to the same sort of failure if the implementation
supported binding of the symbol plist or of a place on the plist.

Additionally, IIUC, it was a goal of the failed proposal to permit
local scope declarations to override global scope proclamations, so
that you could say things like

(proclaim '(special x))
(locally (declare (lexical x))
(defun foo () x))

You can't simulate that effect with symbol-macros alone, since an
error is signalled when trying to establish a symbol macro for a
symbol that's already defined as a global variable. (Having special
and lexical variables with the same name is a bad idea anyhow, so this
is probably a minor issue for people who care about lexical