這是一個家庭作業問題。計劃 - 我試圖擴展此聲明有什麼問題?
問題
我嘗試(整個文件):http://pastebin.com/TS6mByEj
如果你搜索let var = exp1 in body
,這就是我需要根據問題來擴展功能。
當我測試上述樣本代碼,我得到一個錯誤apply-env: No binding for y
(EVAL「令x = 30 中設X = - (X,1) Y = - (X,2) 在 - (X,Y)「)
; The following is execution log
The-next-two-lines-shows-var-and-exp1
(x)
(#(struct:const-exp 30))
diff-exp
#(struct:var-exp x)
#(struct:const-exp 1)
diff-exp
#(struct:var-exp x)
#(struct:const-exp 2)
The-next-two-lines-shows-var-and-exp1
(x y)
(#(struct:diff-exp #(struct:var-exp x) #(struct:const-exp 1)) #(struct:diff-exp #(struct:var-exp x) #(struct:const-exp 2)))
diff-exp
#(struct:var-exp x)
#(struct:var-exp y)
我知道這是很長的語言,但如果任何人都可以親切地帶領我到正確的方向將是非常非常好的。
謝謝!
UPDATE
之前,我評估和命中誤差,新的環境env1
是這樣
(#(struct:extend-env x #(struct:num-val 29) #(struct:extend-env x #(struct:num-val 30) #(struct:extend-env i #(struct:num-val 1) #(struct:extend-env v #(struct:num-val 5) #(struct:extend-env x #(struct:num-val 10) #(struct:empty-env))))))
#(struct:extend-env y #(struct:num-val 28) #(struct:extend-env x #(struct:num-val 30) #(struct:extend-env i #(struct:num-val 1) #(struct:extend-env v #(struct:num-val 5) #(struct:extend-env x #(struct:num-val 10) #(struct:empty-env)))))))
其中之一是#(struct:extend-env y #(struct:num-val 28)
。因此y
存在於將要評估的環境中,但它不是car env1
的一部分。這是cdr env1
然而,我的代碼依賴於car env1
....
對不起,我刪除了我的答案,因爲我誤解了你的問題,而我的答案不會有任何幫助。 – 2012-03-29 05:39:33
@KshitijMehta沒關係。你仍然花時間回覆:)讓我們希望有人能夠在這裏給我一個好頭!謝謝。 – CppLearner 2012-03-29 05:40:52