Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

common-lisp: difference between binding and symbol

What's (in simple terms) the difference between setting a binding (LET) and symbols (=variables) in common lisp?

like image 457
martins Avatar asked Apr 18 '10 22:04

martins


People also ask

What is a symbol in 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.

What does t mean in Lisp?

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.


2 Answers

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.

like image 57
dmitry_vk Avatar answered Oct 02 '22 12:10

dmitry_vk


(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.

like image 43
Amos Avatar answered Oct 02 '22 12:10

Amos