In, for example this let in Common Lisp
(let ((a 5)) (print a))
Is a mutable as with defparameter, or is a constant as is the case with defvar?
In, for example this let in Common Lisp
(let ((a 5)) (print a))
Is a mutable as with defparameter, or is a constant as is the case with defvar?
On
Here's some examples that might clarify this. You can try them at the repl. Try to think about whether they are more like defvar or defparameter
(loop repeat 2 do
(let ((a 1)) (print a) (setf a 5) (print a)))
(loop repeat 2 do
(let ((a (list 1 2)))
(print (first a))
(setf (first a) 5)
(print (first a))))
(loop repeat 2 do
(let ((a '(1 2)))
(print (first a))
(setf (first a) (+ (first a) 5))
(print (first a))))
Hopefully these examples should help you get a better idea of what let does. What happens when you put the third example into the repl is actually implementation dependant and has little to do with let and much more to do with quote.
You can change what
ais bound to, i.e. makearefer to something else:If the value referenced by
ais mutable, you can mutate it:No,
DEFVARdoes not define constants.Then:
What happens is that when you evaluate a
DEFVARform, it first checks whether the symbol is already bound. If this is the case, then the existing value is kept in place. On the other hand,DEFPARAMETERalways reintializes the variable.