谁能解释一下eval
emacs24是如何工作的?从eval
描述:
eval is a built-in function in `C source code'.
(eval FORM &optional LEXICAL)
Evaluate FORM and return its value.
If LEXICAL is t, evaluate using lexical scoping.
这是否意味着,这样的事情应该有效?
(setq lexical-binding t)
(let ((myvarr 42)) (eval 'myvarr t)) ; (void-variable myvarr)
更新:
(setq lexical-binding nil)
;; => nil
(let ((myvarr 42)) (eval 'myvarr))
;; => 42 (#o52, #x2a, ?*)
(setq lexical-binding t)
;; => t
(let ((myvarr 42)) (eval 'myvarr))
;; Debugger entered--Lisp error: (void-variable myvarr)
;; eval(myvarr)
;; (let ((myvarr 42)) (eval (quote myvarr)))
;; (progn (let ((myvarr 42)) (eval (quote myvarr))))
;; eval((progn (let ((myvarr 42)) (eval (quote myvarr)))) t)
;; eval-last-sexp-1((4))
;; eval-last-sexp((4))
;; call-interactively(eval-last-sexp nil nil)
;; call-last-kbd-macro(nil kmacro-loop-setup-function)
;; kmacro-call-macro(nil nil)
;; kmacro-end-or-call-macro(nil)
;; call-interactively(kmacro-end-or-call-macro nil nil)
(ignore-errors (let ((myvarr 42)) (eval 'myvarr)))
;; => nil
(setq lexical-binding nil)
;; => nil
(eval (let ((myvarr 42)) (eval 'myvarr)) t)
;; => 42
(eval '(let ((myvarr 42)) (eval 'myvarr)) t)
;; Debugger entered--Lisp error: (void-variable myvarr)
;; eval(myvarr)
;; (let ((myvarr 42)) (eval (quote myvarr)))
;; eval((let ((myvarr 42)) (eval (quote myvarr))) t)
;; eval((eval (quote (let ((myvarr 42)) (eval (quote myvarr)))) t) nil)
;; eval-last-sexp-1((4))
;; eval-last-sexp((4))
;; call-interactively(eval-last-sexp nil nil)
Emacs 版本:GNU Emacs 24.1.1 (i386-mingw-nt6.1.7600) of 2012-06-10 on MARVIN