With dynamic scope you don't have closures. Eg.
(define val #f)
(define (get-val val)
(lambda ()
val))
(define getter (get-val 5))
(getter) ; => #f
With lexical scope val
from get-val
lives in the returned procedure as a free variable and would return 5
, but in dynamic scope it stopped existing right ather the proceudre was returned. The val
referred in the procedure is whatever bound val
in the dynamic scope. Eg.
(let ((val 10))
(getter)) ; ==> 10
So val
from the let
became the closest binding with that name ad getter
returned that.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…