Closed vanh17 closed 8 years ago
in var, do you think we need to fetch to get the value or just need to do lookup? Warmest, Dr. @Skiadas
I did not find any fetch in the assignment. SO I guess not lol Warmest
This interpreter has no mutation, so no store.
Also, for the clos, do you thing clos (f env) the f here is the whole function expresion right? So if we want to create some clos we have to do (clos f env)
never mind, I finished the whole thing :)))
what do you mean in the call, "bind it to the closure first before evaluate it", do you mean we have to do (bind (fun-name f) (clos-env))? or sth else. I am confused a little bit Warmest Dr. @Skiadas
It should be great if you can tell me about the call function and its purpose. Warmest @Skiadas
Yes if the function is to be able to call itself, it must find a binding for itself (i.e. its closure) in the environment in which it is evaluated. The environment that you packaged in the closure during function definition doesn't contain that, as it didn't exist yet. So just as you extend the environment with a binding for the parameter, you need to further extend it with a binding for the function/closure.
Dear Dr., In the test, is this the way we recursively call the function? (fun 'f 'x (if (value-eq? (var 'x) (num 1)) (pair-e (num 1) (nul)) (pair-e (var 'x) ('f (arith '- (var 'x) (num 1)))))) Dr. @skiadas How can we define the recursively function though should we just need to call 'f or (var 'f) or something else, it keep give me an error,.
You should call your function however you would call any function in your language. If you have the function call in Racket: "(g 2)" what expression would it translate to in your language?
Do you mean (call (var 'f) (arith '+....)) Dr. @Skiadas
Right.
Haris Skiadas Hanover College
On Apr 1, 2016, at 3:29 PM, Van Nguyen Hung Hoang notifications@github.com wrote:
Do you mean (call (var 'f) (arith '+....))
� You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub
So I think I have an infinite loops somehow. Could you please have a loook on my code? Thank you Dr. Skiadas Warmest, @skiadas
One thing I can tell you is that these tests are not right:
(equal? (evaluate (call (fun 'f 'x (if (value-eq? (var 'x) (num 1)) (pair-e (num 1) (nul)) (pair-e (var 'x) (call (var 'f) (arith '- (var 'x) (num 1)))))) (num 3)))
(pair-e (num 3) (pair-e (num 2) (pair-e (num 1) (nul))))))
(with-handlers ([exn:fail? (lambda (exn) #f)])
(equal? (evaluate (call (fun 'f 'x (cond [(value-eq? (var 'x) (num 0)) (num 0)]
[(value-eq? (var 'x) (num 1)) (num 1)]
[#t (arith '+ (call (var 'f) (arith '- (var 'x) (num 2))) (call (var 'f) (arith '- (var 'x) (num 1))))])) (num 3)))
(num 2)))
You should NOT use things like "cond" and "value-eq?" inside the expressions you are supposed to be creating. These will be processed by Racket right away, and they have nothing to do with the interpretation of the function call by your interpreter. They are not being evaluated when your interpreter runs, they are evaluated before it runs.
Try the to type the "call" thing on its own and see what it looks like. No evaluate or nothing, write the "call..." expression in and see what Racket gives you back.
All your function's logic needs to be written in terms of your language, not using Racket constructs
But yes, you are doing some weird stuff in your "call" interpretation. You really need to think about what that code should do, use intermediate variables, write it in WORDS first, etc.
so I am now implementing map-e. However, when I passed your tests it cannot recognize the expression in interpretation? Warmest, Dr. @skiadas
Did you try to have it show you the expression that it is interpreting? I can see at least one place in your map-e where you are using a construct that's not part of your language and that Racket would evaluate too soon before it gets to your interpreter.
I think I did not udpdate it properly, it should be (bool (nul?...) @Skiadas
No, no it shouldn't. Try typing just the "(bool (nul? (snd (var 'lst))))" in the console by itself, without evaluating it in your language. What should happen to it? What does happen to it?
Also make sure you code can handle an empty list.
it gives me (bool #f) ?
Is that right?
no =))), I should type (bool (isnul (var 'lst)))
It should be just (isnul (var 'lst))
It is now working. And I think you are definitly right, I should have print out what my language structure are to match it during my project. But believe me it is so much fun with this assignment. All tests passed. Thank you so much Dr. @skiadas p/s: so I guess this is what all the interpreter build on then :D
Implementing interpreter