What's (in simple terms) the difference between setting a binding (LET) and symbols (=variables) in common lisp?
In LISP, a symbol is a name that represents data objects and interestingly it is also a data object. What makes symbols special is that they have a component called the property list, or plist.
LISP uses the self-evaluating symbol nil to mean false. Anything other than nil means true. Unless we have a reason not to, we usually use the self-evaluating symbol t to stand for true. LISP provides a standard set of logical functions, for example and, or, and not.
Symbols and variables are two very different kinds of entities. Symbol is a name of something; variable is a container for a value. Variable can be named by a symbol.
Binding is an association between a symbol and a variable; when binding is in effect, you can refer to a variable by its name. let
form creates such a binding.
(let ((a 1))) sets the value of a to 1 until the point where the closing bracket which matches the opening bracket before the let is reached, at which point a reverts to whatever it's previous value was (or becomes undefined). You often see a let in the body of a function where you require local variables which need to go out of scope at the end of the function, so you would use a let there.
(setf a 1) sets a to 1 and assumes that either a has been previously defined (whether by defparameter, defvariable or let) or that a is a new special variable that needs a value.
It's a bit more complicated than that but I'm not sure i have the lisp chops to explain it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With