Eval and lexical variables

I am doing a small project just for fun, and I have added support evalto facilitate debugging. But later I discovered a problem:

(let ((x 1))
    (eval (1+ x)))

(defun foo (x form)
    (eval form))
(foo 1 '(1+ x))

The code above will not work. Can anyone explain why and how it works? Many thanks.

+2
source share
1 answer

First though

(let ((x 1))
  (eval (1+ x)))

, (, , -), , , . eval , , . eval 2 - "" ( ) 2.

(defun foo (x form)
  (eval form))

. , - / . (, eval) , .

:

(defun foo (x form)
  (declare (special x))
  (eval form))

lisp, x .

+4

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


All Articles