在another question关于elisp的局部变量的定义,无论受访者提醒,let
是恰当的,强调它不会定义变量是本地的功能。该变量仅限于let
语句。本地到`let`对函数的局部
本地到let
和本地功能有什么区别?是否有另一个构造函数可以为函数的范围定义变量?
使用let
声明函数看起来这样的:
(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..."))))
'let'创建一个局部变量。这是在elisp中创建它的唯一方法。 – sds