Let, eval, and quote behavior

I tried to understand the behavior let. Why did case2 give me an error?

;; case1: worked fine.
(let ((NF 5)) NF)
5

;; case2: got an error
(let ((NF 5)) (eval 'NF))
error: The variable NF is unbound
+4
source share
1 answer

EVALdoes not have access to lexical variables. CLHS says:

Computes the form in the current dynamic environment and zero lexical environment.

If you declare a variable special, it will work because it performs dynamic binding, not lexical binding.

(let ((NF 5))
  (declare (special NF))
  (eval 'NF))
5
+8
source

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


All Articles