Local for `let` versus local for function

In another question regarding the local definitions of variables in Elisp, both respondents report that they letare appropriate and emphasize that they will not define a variable that will be local to the function. The variable is local to the operator only let.

What are the differences between local letand local functions? Is there any other construct that would define a variable for the scope?

A function using the operator letlooks like 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..."))))
+4
source share
2 answers

let , ", let" ", ".

, , . let - , , , , , , let.

+4

?

, "local to the function" , , , , Emacs let ( ).

, ( , ). , , :

(defun func1 ()
  (let ((foo 42))
    (func2)))

(defun func2 ()
  (bound-and-true-p foo))

func1 func2, , , , foo .

func1 42, foo - let, func2.

func1 nil, foo ( ) , func1, func2 ).

, " " , foo let, . let, , (func3 42) :

(defun func3 (foo)
  (func4))

(defun func4 ()
  (bound-and-true-p foo))
0

Source: https://habr.com/ru/post/1674314/


All Articles