diff --git a/project.properties b/project.properties index 7a2efdc..d3a3726 100755 --- a/project.properties +++ b/project.properties @@ -1,9 +1,10 @@ +#Tue, 20 Apr 2010 11:13:19 -0500 #Tue Feb 09 14:02:30 CST 2010 build.dir=build src.dir=src grammar.output.dir=${src.dir}/edu/utexas/cs345/jdblisp/parser build.jar=${build.dir}/JCLisp-${application.version}.${build.number}.jar -build.number=15 +build.number=17 dist.dir=dist javacc.home=${lib.dir}/javacc dist.jar=${dist.dir}/JCLisp-${application.version}.jar diff --git a/src/edu/utexas/cs345/jdblisp/Lambda.java b/src/edu/utexas/cs345/jdblisp/Lambda.java index a552d86..7e3e4ba 100644 --- a/src/edu/utexas/cs345/jdblisp/Lambda.java +++ b/src/edu/utexas/cs345/jdblisp/Lambda.java @@ -1,5 +1,6 @@ package edu.utexas.cs345.jdblisp; +import java.util.ArrayList; /** * Lambda */ @@ -45,8 +46,24 @@ public class Lambda extends FunctionEntry { @Override public SExp call(SymbolTable symbolTable, Seq arguments) throws LispException { + + // we are going to pass a ClosureSymbolTable into the + // FunctionEntry.call() method. But the first thing FE.call() is going + // to do is evaluate the arguments and bind them to the parameters + // expected by the function (lambda in this case). The + // ClosureSymbolTable looks in the closure context first, then in the + // calling context. This is correct inside the body of the closure but + // incorrect for the argument evaluation, which should happen in the + // calling context, so let's preemptivly evaluate the arguments. + Seq evaledArguments; + ArrayList temp = new ArrayList(); + + for (;arguments != null; arguments = arguments.cdr) + temp.add(arguments.car.eval(symbolTable)); + + evaledArguments = new Seq(temp.toArray(new SExp[]{})); return super.call(new ClosureSymbolTable(symbolTable, closure), - arguments); + evaledArguments); } }