uhmanoa-transpiler-project / shaka-scheme

The official repository for the UH Manoa Transpiler Project's Scheme interpreter, Shaka Scheme.
32 stars 24 forks source link

Variadic lambdas are not working properly #17

Closed btwooton closed 7 years ago

btwooton commented 7 years ago

In R7RS scheme, it should be possible to define a lambda procedure of the form:

(lambda x x)

Which will collect any number of arguments into a list and bind the variable x to this list. However, attempts to define and call such a lambda procedure in our REPL program results in the following error message:

Error: DataNode.length: argument is not a list

I will begin exhaustive unit testing to determine the source of this issue and hopefully correct it.

btwooton commented 7 years ago

Variadic lambdas are now working.

The algorithm in Procedure.call() was assuming that the formal parameters of the lambda expression were in a proper list, without checking for the other possible forms

(lambda x x)

and

(lambda (x y . z) ...)

I have extended the method with a conditional that checks if the formal parameter is a single symbol, in which case it wraps the arguments from the vector into a list and binds that list to the formal parameter symbol in the curr_env pointer. The method then continues its normal process of evaluating the procedure body.

I have written a unit test confirming that this functionality is now working, and have also given it a test drive in the REPL. A similar extension will likely need to be made to accommodate the hybrid lambda form (lambda (x y . z) ...). I will work on that later but am now considering tackling recursion because that currently does not seem to be working properly either. Issue closed

-- Troy