Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Behavior of let, eval, and quote

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
like image 628
Peter Hwang Avatar asked Feb 11 '23 04:02

Peter Hwang


1 Answers

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
like image 114
Barmar Avatar answered Mar 12 '23 03:03

Barmar