In some docs,I found that they say the answer is *var* means global variable.
But when I try, I couldn’t make sure that.
FIRST-PACKAGE[27]> (defvar b 1)
B
FIRST-PACKAGE[28]> b
1
FIRST-PACKAGE[29]> (defun add_b (x) (+ x b))
ADD_B
FIRST-PACKAGE[30]> (add_b 3)
4
FIRST-PACKAGE[31]>
In my example, b is still not global if that answer is right.
But why the function add_b still can use it?
How to understand this example and *var*?
Thank you~
All right. In Common Lisp there are effectively two types of variables: the ones you use all the time, which are lexically bound, and “special” variables, which are dynamically bound. “Special” variables are created with
defvar,defparameter, or a declaration. The*earmuffs*are a convention that exists to remind Lisp programmers that a variable is special. Here are some examples:As you can see, changing the value of a special variable in a
letmakes the value change “trickle down” to all of the function calls in thatlet, while value changes of a regular, lexically-bound variable don’t get passed down, In fact, lexically bound variables are looked up by moving up the scopes that are located where the function wan defined, while special variables are looked up by moving up the scopes where the function was called. The*earmuffs*are useful to stop programmers from accidentally rebinding a special variable, because they make special variables look different.