Scheme - What is wrong with my attempt to extend this declaration?
Posted
by
CppLearner
on Stack Overflow
See other posts from Stack Overflow
or by CppLearner
Published on 2012-03-29T05:26:04Z
Indexed on
2012/03/29
5:29 UTC
Read the original article
Hit count: 153
This is a homework question.
Question
My attempt (the whole file): http://pastebin.com/vt3Q3dqs
If you search let var = exp1 in body
, that's the function I need to extend according to the question.
When I test the sample code above, I get an error apply-env: No binding for y
(eval "let x = 30 in let x = -(x,1) y = -(x,2) in -(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)
As you can see, when the interperter reads the last line -(x,y)
it complains because there is no binding. What did I do wrong?
I know this is really long language, but if anyone can kindly lead me to the right direction would be really really nice.
Thank you!
© Stack Overflow or respective owner