mwatts15 / Crono

Scheme project for CS345
0 stars 0 forks source link

Fix lets returning functions being evaluated(?) #21

Closed tvarney closed 11 years ago

tvarney commented 11 years ago

Currently, the example given in the project requirements handout states that the code:

((let ((f (\ (x) x))) f) (let ((x 4)) x))

should evaluate fine, with a result of 4. However, the interpreter currently does not evaluate this, instead throwing an InterpreterException with the message

Invalid Function Application: 4 is not a function in (4)

We need to get this statement working properly before Thursday.

cvidal commented 11 years ago

Looks like let is trying to evaluate its list of substitutions even when they're not function applications. (let () 4) works as expected. (let (x 3) x) tries to apply 3. (let ((x ((\ (a) (+ a 3)) 3))) x) tries to apply 6, so at least function application is working inside the substitution list. It seems whatever check is happening for basic types in let is failing when it shouldn't.

That's just from playing around a bit with the interpreter, I'll take a closer look at the source later.

tvarney commented 11 years ago

I agree, it looks like a problem with let itself; for some reason (let ((x 4) x) returns (4), when it should be returning 4.

tvarney commented 11 years ago

Fixed; issue was that Let (and letrec) needed to get the car() of the second value in each list since the parser guarantees that all Cons are Nil terminated. Added a bit of logic to check if the cdr() of the list is a cons, then resolve that using car(). The example given by Dr. Canata now works.