>>>>> "Holger" == Holger Schauer <schauer(a)coling.uni-freiburg.de> writes:
>>>>> "MS" == Michael Sperber schrieb am 22 Aug 1998 16:12:54 +0200:
MS> (define-syntax foo (syntax-rules () ((foo) bar)))
MS> BAR always refers to the binding of BAR lexically visible in the
MS> macro definition.
Holger> Hmm.
Holger> (setq bar 23)
Holger> (defmacro foo () bar)
Holger> (foo) => 23
Holger> (let ((bar 42)) (foo)) => 23
Holger> (setq bar 57)
Holger> (foo) => 23
Holger> (let ((bar 42)) (foo)) => 57
Holger> So, what do you want ? That foo always refers to 23 regardless whether
Holger> I have changed the value of bar in the mean time ?
No. I think the problem is that many C and Common Lisp programmers
confuse the concepts of "binding" and "assignment."
Binding a value to a name means creating a new association between the
name and the value.
Assigning a value to a name means changing the value an
already-existing binding.
These are two very different things. Sadly, in C it's possible to
create bindings without values, and in Common Lisp, assignment (via
setq) may create the binding if it doesn't exist yet.
Thus, in your example,
(setq bar 23)
[if done in fresh CL session]
creates a binding which associates 23 with BAR, and:
(setq bar 57)
modifies the binding created previously.
Your example evaluates BAR at macro-definition time which surely is
not what you intended. (I.e., (foo) expands to 23, regardless.) What
I want is:
(setq 23)
(defmacro foo () 'bar)
(foo) => 23
(let ((bar 42)) (foo)) => 23 [note: CL actually yields 42]
(setq bar 57)
(foo) => 57
(let ((bar 42)) (foo)) => 57 [note: CL actually yields 42]
Note that this is exactly what actually *would* happen if you wrote:
(defun foo () bar)
instead of the defmacro.
--
Cheers =8-} Chipsy
Friede, Völkerverständigung und überhaupt blabla