我正在阅读编程语言:应用程序和解释书第 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