>>5
Yes, that
SETF will expand into a
SETQ, unless
prog is a symbol macro, which it probably isn't. If
prog was declaimed to be a special variable, either directly(
(DECLAIM (SPECIAL PROG))) or indirectly(
DEFVAR/
DEFPARAMETER), that
SETF would not be undefined, it would also not be undefined if that statement was wrapped in a
LET that had
prog as a lexical variable. I'm not touching the problem of
prog not having earmuff's if it is a special variable.
More details at
http://www.lispworks.com/documentation/lw51/CLHS/Body/s_setq.htm . ``setq may be used for assignment of both lexical and dynamic variables.f any var refers to a binding made by symbol-macrolet, then that var is treated as if setf (not setq) had been used.'' Since
prog has not been declared or defined anywhere as a lexical or special variable, nor as a symbol macro, the behaviour is undefined.
What will an implementation do when it encounters an undefined variable? Common cases are:
1.
(setq var ...) gets treated as it would be
(setf (symbol-value 'var) ...), which sets the symbol's value slot, without proclaiming/declaiming
var as special. However, if you were to locally declare it special, you could access the value, or via
(symbol-value 'var). Of course, such implementations may extend this by treating the undefined variable locally special, but not declaiming it globally special everywhere. It's a bit of a tricky issue. The reason for that expansion is that
SETQ's name comes from SET QUOTED, which meant that
SETQ was supposed to abbreviate the fairly common form
(SET 'VAR ...) in old lisps (with only dynamic scope).
SET still exists today and it more or less means the same as
(setf (symbol-value ...) ...).
2. The other common treatmeant is the same as 1, but with proclaiming the variable globally special (CMUCL does this, I think SBCL removed this behaviour in their fork, but I'm not 100% sure). This is a bit more agressive as the next time someone uses that variable, it would be automatically considered special, thus altering the behaviour unadvertedly.
Another common thing to do is signal a WARNING that the variable is undefined and then proceed with setting the value slot of the global symbol. SBCL does this.