diff --git a/src/function/UserDefinedFunction.java b/src/function/UserDefinedFunction.java index 525a803..648b68b 100644 --- a/src/function/UserDefinedFunction.java +++ b/src/function/UserDefinedFunction.java @@ -37,7 +37,7 @@ public class UserDefinedFunction extends LispFunction { SymbolTable callingScope = executionContext.getScope(); executionContext.setScope(functionScope); - SExpression lastEvaluation = null; + SExpression lastEvaluation = Nil.getInstance(); for (Cons expression = body; expression.consp(); expression = (Cons) expression.getCdr()) lastEvaluation = EVAL.eval(expression.getCar()); diff --git a/src/function/builtin/special/DEFUN.java b/src/function/builtin/special/DEFUN.java index 2e0b7b3..23b0b2f 100644 --- a/src/function/builtin/special/DEFUN.java +++ b/src/function/builtin/special/DEFUN.java @@ -17,7 +17,7 @@ public class DEFUN extends LispFunction { public DEFUN() { this.argumentValidator = new ArgumentValidator("DEFUN"); - this.argumentValidator.setMinimumNumberOfArguments(3); + this.argumentValidator.setMinimumNumberOfArguments(2); this.argumentValidator.setFirstArgumentExpectedType(Symbol.class); this.lambdaListIsListValidator = new ArgumentValidator("DEFUN|lambda-list|"); diff --git a/src/function/builtin/special/LAMBDA.java b/src/function/builtin/special/LAMBDA.java index 384ba93..3ca7e3c 100644 --- a/src/function/builtin/special/LAMBDA.java +++ b/src/function/builtin/special/LAMBDA.java @@ -34,7 +34,7 @@ public class LAMBDA extends LispFunction { public LAMBDA() { this.argumentValidator = new ArgumentValidator("LAMBDA"); this.argumentValidator.setFirstArgumentExpectedType(Cons.class); - this.argumentValidator.setMinimumNumberOfArguments(2); + this.argumentValidator.setMinimumNumberOfArguments(1); this.lambdaListValidator = new ArgumentValidator("LAMBDA|lambda-list|"); this.lambdaListValidator.setEveryArgumentExpectedType(Symbol.class); diff --git a/test/function/builtin/special/DEFUNTester.java b/test/function/builtin/special/DEFUNTester.java index ae6ba24..4e2163a 100644 --- a/test/function/builtin/special/DEFUNTester.java +++ b/test/function/builtin/special/DEFUNTester.java @@ -26,7 +26,15 @@ public class DEFUNTester { @Test public void testDefun() { - String input = "(defun f () nil)"; + String input = "(defun f () t)"; + + assertSExpressionsMatch(parseString("f"), evaluateString(input)); + assertSExpressionsMatch(parseString("t"), evaluateString("(f)")); + } + + @Test + public void testDefunWithEmptyBody() { + String input = "(defun f ())"; assertSExpressionsMatch(parseString("f"), evaluateString(input)); assertSExpressionsMatch(parseString("()"), evaluateString("(f)")); @@ -68,8 +76,8 @@ public class DEFUNTester { } @Test(expected = TooFewArgumentsException.class) - public void testApplyWithTooFewArguments() { - evaluateString("(defun x ())"); + public void testDefunWithTooFewArguments() { + evaluateString("(defun x)"); } } diff --git a/test/function/builtin/special/LAMBDATester.java b/test/function/builtin/special/LAMBDATester.java index 47885d0..f1a9f13 100644 --- a/test/function/builtin/special/LAMBDATester.java +++ b/test/function/builtin/special/LAMBDATester.java @@ -17,6 +17,13 @@ public class LAMBDATester { assertSExpressionsMatch(parseString("(LAMBDA (X) X)"), evaluateString(input)); } + @Test + public void testLambdaWithNoBody() { + String input = "(lambda ())"; + + assertSExpressionsMatch(parseString("(LAMBDA ())"), evaluateString(input)); + } + @Test public void lambdaExpressionIsLambdaExpression() { Cons lambdaExpression = new Cons(new Symbol("LAMBDA"), @@ -74,7 +81,7 @@ public class LAMBDATester { @Test(expected = TooFewArgumentsException.class) public void testLambdaWithTooFewArguments() { - evaluateString("(lambda ())"); + evaluateString("(lambda)"); } @Test