Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

Use this tag for questions about variables local to a function, defined by let-binding them.

Like most programming languages, Lisp in general and Elisp in particular allow for defining local variables in a function. The scope of such variables is limited to the function within which they are defined.

Local variables are defined by let-binding them. For example, when defining a function func, you can define a local variable v as follows:

(defun func (arg1 arg2)
   (let ((v nil))

Within the body of the function, the variable v can be used as "scratch paper" to calculate and remember partial results. When the function is called and the let-form is evaluated, v is bound (in this case to nil) and can be used as any other variable in the body of the form. But when the let-form evaluation ends, the variable disappears.

It is worth noting that the arguments to the function are also local variables: they disappear when the evaluation of the function body is complete.

There are a few different forms of let - see the links for details.

Useful links

Local variables section in the Elisp Reference Manual

let section in the Introduction to Elisp Manual