From 35ef281733827426ad6ce83f4f79b4146c2854ec Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Sun, 15 Jan 2017 19:17:19 -0500 Subject: [PATCH] Refactored the built in function quote --- src/function/builtin/special/QUOTE.java | 40 +++++++------------------ 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/src/function/builtin/special/QUOTE.java b/src/function/builtin/special/QUOTE.java index c1533d4..eac3077 100644 --- a/src/function/builtin/special/QUOTE.java +++ b/src/function/builtin/special/QUOTE.java @@ -1,41 +1,23 @@ package function.builtin.special; -import function.LispFunction; -import function.builtin.cons.LENGTH; +import function.*; import sexpression.*; -/** - * QUOTE represents the QUOTE form in Lisp. - */ public class QUOTE extends LispFunction { - // The number of arguments that QUOTE takes. - private static final int NUM_ARGS = 1; + private ArgumentValidator argumentValidator; - public SExpression call(Cons argList) { - // retrieve the number of arguments passed to QUOTE - int argListLength = LENGTH.getLength(argList); - - // make sure we have received exactly one argument - if (argListLength != NUM_ARGS) { - Cons originalSExpr = new Cons(new Symbol("QUOTE"), argList); - String errMsg = "too " + - ((argListLength > NUM_ARGS) ? "many" : "few") + - " arguments given to QUOTE: " + originalSExpr; - - throw new RuntimeException(errMsg); - } - - return argList.getCar(); + public QUOTE() { + this.argumentValidator = new ArgumentValidator("QUOTE"); + this.argumentValidator.setExactNumberOfArguments(1); + } + + public SExpression call(Cons argumentList) { + argumentValidator.validate(argumentList); + + return argumentList.getCar(); } - /** - * Determine if the arguments passed to this Lisp function should be - * evaluated. - * - * @return - * false - */ public boolean evaluateArguments() { return false; }