In another question regarding local variable definitions in Elisp, both respondents advise that let
is appropriate and emphasize that it will not define the variable to be local to the function. The variable is local only to the let
statement.
What is the distinction between local to let
and local to the function? Is there another construct which would define the variable for the scope of the function?
The function using a let
statement looks this:
(defun test-search (string)
"Searches for STRING in document.
Displays message 'Found!' or 'Not found...'. Places point after word
when found; fixed otherwise."
(interactive "sEnter search word: ")
(let ((found (save-excursion
(beginning-of-buffer)
(search-forward string nil t nil))))
(if found
(progn
(goto-char found)
(message "Found!"))
(message "Not found..."))))
Since the let
makes up the whole body of your function in your example, your "variables local to let" are indistinguishable from "variables local to the function".
For that reason, no there is no separate construct to introduce variables local to a function. let
is that construct, which can be used for variables valid over the whole function, or for variables valid over a small subset, depending on where you place the let
.