Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apparent argument binding issues when attempting to call user defined procedure with multiple arguments #16

Closed
btwooton opened this issue Apr 28, 2017 · 2 comments
Assignees

Comments

@btwooton
Copy link
Collaborator

I attempted to define the following simple lambda procedure in our REPL today:

(define add (lambda (x y) (+ x y)))

The procedure is seemingly successfully parsed in, however when I attempt to call the procedure as follows:

(add 1 2)

I get back the following error:

Error: eval.Variable: variable y is undefined

Not sure what specifically is causing this issue, but it seems as thought the last parameter in the parameter list is not being properly bound to its argument at call time. Notably, the following extended definition:

(define add3 (lambda (x y z) (+ x y z)))

With call:

(add3 1 2 3)

Errors similarly with:

Error: eval.Variable: variable z is undefined

The last parameter is not being bound to its argument successfully. I will attempt to resolve this issue over the week-end when I have time, but thought I would point it out to everyone, because it should be somewhat trivial to resolve.

-Troy

@btwooton
Copy link
Collaborator Author

btwooton commented May 3, 2017

Famous last words...upon closer inspection, I am having a very difficult time tracking down the origin of this bug. Additionally, variadic lambdas are not working properly either. I attempted to define the following simple variadic lambda:

(define my-list (lambda x x))

This procedure should be able to take in an arbitrary number of arguments and return as its result a list containing all of the arguments that it got. However, an attempt to call the procedure as follows:

(my-list 1 2 3)

Errors with:

Error: DataNode.length: argument is not a list

Something is causing our procedure call/evaluation semantics to fail with both multi-argument lambdas and variadic lambdas. To make matters more confusing, they seem to be failing in different ways. I am going to attempt some exhaustive unit testing at the different links in the evaluation chain to see if I can elicit what is happening here.

@btwooton
Copy link
Collaborator Author

btwooton commented May 4, 2017

Fixed the issue behind multi-argument lambdas. The issue was in Procedure_impl.h, inside of the call() method. The for loop in which the argument bindings were occurring was looping while i < args_list_root->length(). This was a subtle bug: the fact that we were performing args_list_root = args_list_root->cdr() inside of the body of this same loop was undermining this check, and we failed to loop the final time needed to bind the last argument. The fix was simple: save the length of the arguments list in a variable prior to entering the for loop, and check the value of i against that original length instead of the length of the mutated arguments list.

@btwooton btwooton closed this as completed May 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant