I was trying to understand the behavior of let
.
Why does case2 throw 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
EVAL
doesn't have access to lexical variables. The CLHS says:
Evaluates form in the current dynamic environment and the null lexical environment.
If you declare the variable special
it will work, since this performs a dynamic binding rather than a lexical binding.
(let ((NF 5))
(declare (special NF))
(eval 'NF))
5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With