>>20
There is actually a difference between that and the
defvar. In your
defmacro, 3.14 would be substituted by the compiler in place of pi when macro expansion is performed (actually, not in place of
pi, but
(pi), as
pi is just a symbol, and not just
(pi), but in places where
(pi) would be macroexpanded or meant to be evaluated).
Anyways,
defvar/defperameter isn't even the recommended solution to that, it's supposed to be a constant, which means
defconstant, also the implementation suggests that it should be a long float. Here's the code my implementation has for it:
(defconstant pi
#!+long-float 3.14159265358979323846264338327950288419716939937511l0
#!-long-float 3.14159265358979323846264338327950288419716939937511d0)
defconstant defines a global variable which should not be modified, and which the compiler can expand upon compilation (and it usually does so). If you want to force the expansion in all implementations, you should instead use a
symbol macro, although that's a bit abusive for constants.
For example:
(define-symbol-macro +pi+ 3.14159265358979323846264338327950288419716939937511)
Oh, and in a related note, while CL doesn't actually support lexically scoped globals, they can be implemented (in about a page or two of code) using symbol macros, macros and a few other language features.