Abandoning dynamic scope
Wednesday, February 6th, 2008With eval evaluating lambda to capture an environment, the function and funarg forms are no longer needed. They are replaced by lambda and proc.
Then dynamic scoping is abandoned by evaluating the function position to retrieve a procedure that carries its own environment.
(#t (apply
(eval (car form) env)
(evlis (cdr form) env)
env
)
)
The lambda recognition can be removed from apply.
The original Lisp interpreter allowed an arbitrary level of indirection. The apply function would follow a chain of atom definitions to find a lambda form. Eliminating lambda and re-evaluation of the function form in apply eliminates all usage of the env argument. At which point, removal of the env argument brings apply closer to the Scheme and Common Lisp versions.
The apply function is now much simpler…
apply =
(lambda (fn args)
(cond
((pproc? fn) (apply-pproc (car(cdr fn)) args))
((eq? (car fn) (quote proc)) (eval
(car(cdr(cdr(cdr fn))))
(mkenv
(car(cdr(cdr fn)))
args
(cdr (car(cdr fn)))
)
)
)
(#t (quote ()))
)
)