SICP exercise 4.5
This page is a followup of this.
Our goal is this.
(define result 1)
(cond ((assoc 'b '((b 2))) => (lambda (x) (+ result (cadr x))))
;; evaluates to 3
My evaluator expands the expression to this.
(let ((result (assoc 'b '((b 2))))) (if result ((lambda (x) (+ result (cadr x))) result) false))
When the environment has a variable named result, it encounts a name collision.
I can escape the problem easily like this.
(let ((result_ (assoc 'b '((b 2))))) ; change result to result_
((lambda (x) (+ result (cadr x))) result_)
It runs correctly only in the situation. However this is not the solution that he want.
The GYNSYM system is a good idea.
My solution is this.
I introduce a reserved word like *COND->IF_RESULT* in my system.