vanh17 / ProgLangAssignments

Assignments for Programming Languages course
0 stars 0 forks source link

interpreter #203

Closed vanh17 closed 8 years ago

vanh17 commented 8 years ago

Implementing interpreter

vanh17 commented 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

vanh17 commented 8 years ago

I did not find any fetch in the assignment. SO I guess not lol Warmest

skiadas commented 8 years ago

This interpreter has no mutation, so no store.

vanh17 commented 8 years ago

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)

vanh17 commented 8 years ago

never mind, I finished the whole thing :)))

vanh17 commented 8 years ago

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

vanh17 commented 8 years ago

It should be great if you can tell me about the call function and its purpose. Warmest @Skiadas

skiadas commented 8 years ago

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.

vanh17 commented 8 years ago

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,.

skiadas commented 8 years ago

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?

vanh17 commented 8 years ago

Do you mean (call (var 'f) (arith '+....)) Dr. @Skiadas

skiadas commented 8 years ago

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

vanh17 commented 8 years ago

So I think I have an infinite loops somehow. Could you please have a loook on my code? Thank you Dr. Skiadas Warmest, @skiadas

skiadas commented 8 years ago

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

skiadas commented 8 years ago

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.

vanh17 commented 8 years ago

so I am now implementing map-e. However, when I passed your tests it cannot recognize the expression in interpretation? Warmest, Dr. @skiadas

skiadas commented 8 years ago

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.

vanh17 commented 8 years ago

I think I did not udpdate it properly, it should be (bool (nul?...) @Skiadas

skiadas commented 8 years ago

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?

skiadas commented 8 years ago

Also make sure you code can handle an empty list.

vanh17 commented 8 years ago

it gives me (bool #f) ?

skiadas commented 8 years ago

Is that right?

vanh17 commented 8 years ago

no =))), I should type (bool (isnul (var 'lst)))

vanh17 commented 8 years ago

It should be just (isnul (var 'lst))

vanh17 commented 8 years ago

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