我正在阅读《编程语言:应用程序和解释》一书第 6 章 http://cs.brown.edu/courses/cs173/2012/book/From_Substitution_to_Environments.html
我已经按照书中所述应用了修复程序,但缺点是没有将类型添加到源代码中引用的空列表中。 我认为这是一个按值传递/按引用传递的事情,有关于如何在不作为参数传递时设置 mt-env 的线索吗?
#lang plai-typed
;; Binding types
(define-type Binding
[bind (name : symbol) (val : number)])
;; some helper functions:
(define-type-alias Env (listof Binding))
(define mt-env empty)
(define extend-env cons)
;; testing function
(define (addBinding [b : Binding] [env : Env])
(extend-env b env)
)
(addBinding (bind 'x 5) mt-env) ;; returns (list (bind x 5))
(display mt-env) ;; returns empty list
如果需要的话,下面是上下文的完整代码的链接,interp函数的appC案例是我的问题区域的具体位置,谢谢。 https://github.com/MickDuprez/plai/blob/master/Chapter%206/chapter-6.rkt
最佳答案
在重新阅读本章最后部分几次后,我认为没有一个简单的解决方案可以解决这个问题。 “更改”仅使修改后的解释器的行为与之前的“替代”解释器相同,但通过特殊的测试用例突出了范围问题。
这在下一部分“6.4 范围”中被回避,作者写道:
"The broken environment interpreter above implements what is known as dynamic scope."
我确信这个问题会在以后的章节中得到解决,无论如何感谢您的阅读。
关于scheme - 类型的空列表不起作用的缺点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38601874/