From 35406b9f036064e6fcaac115bf19d70cbb18670d Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Sat, 10 Nov 2018 08:26:50 -0500 Subject: [PATCH] Convert remaining built in functions to kotlin --- src/main/kotlin/function/ArgumentValidator.kt | 2 +- src/main/kotlin/function/builtin/Eval.kt | 2 +- src/main/kotlin/function/builtin/Funcall.kt | 2 +- .../kotlin/function/builtin/cons/APPEND.java | 74 ------------------- .../kotlin/function/builtin/cons/Append.kt | 63 ++++++++++++++++ .../kotlin/function/builtin/cons/CONS.java | 29 -------- .../kotlin/function/builtin/cons/Construct.kt | 24 ++++++ .../kotlin/function/builtin/cons/FIRST.java | 27 ------- .../kotlin/function/builtin/cons/First.kt | 23 ++++++ .../kotlin/function/builtin/cons/LENGTH.java | 65 ---------------- .../kotlin/function/builtin/cons/LIST.java | 29 -------- .../kotlin/function/builtin/cons/Length.kt | 39 ++++++++++ src/main/kotlin/function/builtin/cons/List.kt | 28 +++++++ .../kotlin/function/builtin/cons/REST.java | 27 ------- src/main/kotlin/function/builtin/cons/Rest.kt | 23 ++++++ .../kotlin/function/builtin/math/DIVIDE.java | 53 ------------- .../kotlin/function/builtin/math/Divide.kt | 41 ++++++++++ .../kotlin/function/builtin/math/MINUS.java | 38 ---------- .../kotlin/function/builtin/math/MODULO.java | 44 ----------- .../function/builtin/math/MULTIPLY.java | 31 -------- .../function/builtin/math/MathFunction.java | 43 ----------- .../function/builtin/math/MathFunction.kt | 27 +++++++ .../kotlin/function/builtin/math/Minus.kt | 32 ++++++++ .../kotlin/function/builtin/math/Module.kt | 36 +++++++++ .../kotlin/function/builtin/math/Multiply.kt | 27 +++++++ .../kotlin/function/builtin/math/PLUS.java | 31 -------- src/main/kotlin/function/builtin/math/Plus.kt | 26 +++++++ .../function/builtin/math/REMAINDER.java | 34 --------- .../kotlin/function/builtin/math/Remainder.kt | 31 ++++++++ .../function/builtin/predicate/NumericLess.kt | 6 +- .../kotlin/function/builtin/special/Define.kt | 2 +- .../function/builtin/special/DefineSpecial.kt | 1 - .../function/builtin/special/Defmacro.kt | 1 - .../kotlin/function/builtin/special/Lambda.kt | 2 +- .../kotlin/function/builtin/special/Setq.kt | 2 +- src/main/kotlin/table/SymbolTable.kt | 4 +- .../cons/{APPENDTest.java => AppendTest.java} | 2 +- .../{CONSTest.java => ConstructTest.java} | 2 +- .../cons/{FIRSTTest.java => FirstTest.java} | 2 +- .../cons/{LENGTHTest.java => LengthTest.java} | 2 +- .../cons/{LISTTest.java => ListTest.java} | 4 +- .../cons/{RESTTest.java => RestTest.java} | 2 +- .../math/{DIVIDETest.java => DivideTest.java} | 4 +- .../math/{MINUSTest.java => MinusTest.java} | 2 +- .../math/{MODULOTest.java => ModuleTest.java} | 4 +- .../{MULTIPLYTest.java => MultiplyTest.java} | 2 +- .../math/{PLUSTest.java => PlusTest.java} | 2 +- ...{REMAINDERTest.java => RemainderTest.java} | 4 +- 48 files changed, 445 insertions(+), 556 deletions(-) delete mode 100644 src/main/kotlin/function/builtin/cons/APPEND.java create mode 100644 src/main/kotlin/function/builtin/cons/Append.kt delete mode 100644 src/main/kotlin/function/builtin/cons/CONS.java create mode 100644 src/main/kotlin/function/builtin/cons/Construct.kt delete mode 100644 src/main/kotlin/function/builtin/cons/FIRST.java create mode 100644 src/main/kotlin/function/builtin/cons/First.kt delete mode 100644 src/main/kotlin/function/builtin/cons/LENGTH.java delete mode 100644 src/main/kotlin/function/builtin/cons/LIST.java create mode 100644 src/main/kotlin/function/builtin/cons/Length.kt create mode 100644 src/main/kotlin/function/builtin/cons/List.kt delete mode 100644 src/main/kotlin/function/builtin/cons/REST.java create mode 100644 src/main/kotlin/function/builtin/cons/Rest.kt delete mode 100644 src/main/kotlin/function/builtin/math/DIVIDE.java create mode 100644 src/main/kotlin/function/builtin/math/Divide.kt delete mode 100644 src/main/kotlin/function/builtin/math/MINUS.java delete mode 100644 src/main/kotlin/function/builtin/math/MODULO.java delete mode 100644 src/main/kotlin/function/builtin/math/MULTIPLY.java delete mode 100644 src/main/kotlin/function/builtin/math/MathFunction.java create mode 100644 src/main/kotlin/function/builtin/math/MathFunction.kt create mode 100644 src/main/kotlin/function/builtin/math/Minus.kt create mode 100644 src/main/kotlin/function/builtin/math/Module.kt create mode 100644 src/main/kotlin/function/builtin/math/Multiply.kt delete mode 100644 src/main/kotlin/function/builtin/math/PLUS.java create mode 100644 src/main/kotlin/function/builtin/math/Plus.kt delete mode 100644 src/main/kotlin/function/builtin/math/REMAINDER.java create mode 100644 src/main/kotlin/function/builtin/math/Remainder.kt rename src/test/kotlin/function/builtin/cons/{APPENDTest.java => AppendTest.java} (97%) rename src/test/kotlin/function/builtin/cons/{CONSTest.java => ConstructTest.java} (96%) rename src/test/kotlin/function/builtin/cons/{FIRSTTest.java => FirstTest.java} (96%) rename src/test/kotlin/function/builtin/cons/{LENGTHTest.java => LengthTest.java} (96%) rename src/test/kotlin/function/builtin/cons/{LISTTest.java => ListTest.java} (93%) rename src/test/kotlin/function/builtin/cons/{RESTTest.java => RestTest.java} (96%) rename src/test/kotlin/function/builtin/math/{DIVIDETest.java => DivideTest.java} (94%) rename src/test/kotlin/function/builtin/math/{MINUSTest.java => MinusTest.java} (95%) rename src/test/kotlin/function/builtin/math/{MODULOTest.java => ModuleTest.java} (96%) rename src/test/kotlin/function/builtin/math/{MULTIPLYTest.java => MultiplyTest.java} (95%) rename src/test/kotlin/function/builtin/math/{PLUSTest.java => PlusTest.java} (95%) rename src/test/kotlin/function/builtin/math/{REMAINDERTest.java => RemainderTest.java} (95%) diff --git a/src/main/kotlin/function/ArgumentValidator.kt b/src/main/kotlin/function/ArgumentValidator.kt index 96bd864..4f349be 100644 --- a/src/main/kotlin/function/ArgumentValidator.kt +++ b/src/main/kotlin/function/ArgumentValidator.kt @@ -1,7 +1,7 @@ package function import error.LispException -import function.builtin.cons.LENGTH.getLength +import function.builtin.cons.Length.Companion.getLength import sexpression.Cons import sexpression.DisplayName import sexpression.SExpression diff --git a/src/main/kotlin/function/builtin/Eval.kt b/src/main/kotlin/function/builtin/Eval.kt index 0034853..6b8233f 100644 --- a/src/main/kotlin/function/builtin/Eval.kt +++ b/src/main/kotlin/function/builtin/Eval.kt @@ -4,7 +4,7 @@ import error.LispException import function.ArgumentValidator import function.FunctionNames import function.LispFunction -import function.builtin.cons.LIST.makeList +import function.builtin.cons.List.Companion.makeList import function.builtin.special.Lambda.Lambda.createFunction import function.builtin.special.Lambda.Lambda.isLambdaExpression import function.builtin.special.Recur.RecurNotInTailPositionException diff --git a/src/main/kotlin/function/builtin/Funcall.kt b/src/main/kotlin/function/builtin/Funcall.kt index 761e3fd..9946a20 100644 --- a/src/main/kotlin/function/builtin/Funcall.kt +++ b/src/main/kotlin/function/builtin/Funcall.kt @@ -4,7 +4,7 @@ import function.ArgumentValidator import function.FunctionNames import function.LispFunction import function.builtin.Apply.Companion.apply -import function.builtin.cons.LIST.makeList +import function.builtin.cons.List.Companion.makeList import sexpression.Cons import sexpression.SExpression diff --git a/src/main/kotlin/function/builtin/cons/APPEND.java b/src/main/kotlin/function/builtin/cons/APPEND.java deleted file mode 100644 index d75edea..0000000 --- a/src/main/kotlin/function/builtin/cons/APPEND.java +++ /dev/null @@ -1,74 +0,0 @@ -package function.builtin.cons; - -import function.ArgumentValidator; -import function.FunctionNames; -import function.LispFunction; -import sexpression.Cons; -import sexpression.Nil; -import table.FunctionTable; - -@FunctionNames({ "APPEND" }) -public class APPEND extends LispFunction { - - public static Cons append(Cons firstList, Cons secondList) { - return lookupAppend().appendLists(firstList, secondList); - } - - private static APPEND lookupAppend() { - return (APPEND) FunctionTable.INSTANCE.lookupFunction("APPEND"); - } - - private ArgumentValidator argumentValidator; - private ArgumentValidator firstListValidator; - - public APPEND(String name) { - this.argumentValidator = new ArgumentValidator(name); - this.argumentValidator.setExactNumberOfArguments(2); - this.argumentValidator.setEveryArgumentExpectedType(Cons.class); - this.firstListValidator = new ArgumentValidator(name + "|first-list|"); - } - - @Override - public Cons call(Cons argumentList) { - argumentValidator.validate(argumentList); - - Cons rest = (Cons) argumentList.getRest(); - Cons firstList = (Cons) argumentList.getFirst(); - Cons secondList = (Cons) rest.getFirst(); - - return appendLists(firstList, secondList); - } - - private Cons appendLists(Cons firstList, Cons secondList) { - firstListValidator.validate(firstList); - - if (firstList.isNull()) - return secondList; - - Cons appendedLists = copy(firstList); - getLastItem(appendedLists).setRest(secondList); - - return appendedLists; - } - - private Cons copy(Cons list) { - Cons newList = new Cons(list.getFirst(), Nil.INSTANCE); - Cons builder = newList; - - for (Cons iterator = (Cons) list.getRest(); iterator.isCons(); iterator = (Cons) iterator.getRest()) { - builder.setRest(new Cons(iterator.getFirst(), Nil.INSTANCE)); - builder = (Cons) builder.getRest(); - } - - return newList; - } - - private Cons getLastItem(Cons list) { - Cons tail = list; - - while (tail.getRest().isCons()) - tail = (Cons) tail.getRest(); - - return tail; - } -} diff --git a/src/main/kotlin/function/builtin/cons/Append.kt b/src/main/kotlin/function/builtin/cons/Append.kt new file mode 100644 index 0000000..a5cfd53 --- /dev/null +++ b/src/main/kotlin/function/builtin/cons/Append.kt @@ -0,0 +1,63 @@ +package function.builtin.cons + +import function.ArgumentValidator +import function.FunctionNames +import function.LispFunction +import sexpression.Cons +import sexpression.Nil +import table.FunctionTable + +@FunctionNames("APPEND") +class Append(name: String) : LispFunction() { + + private val argumentValidator = ArgumentValidator(name).apply { + setExactNumberOfArguments(2) + setEveryArgumentExpectedType(Cons::class.java) + } + + private val firstListValidator = ArgumentValidator("$name|first-list|") + + override fun call(argumentList: Cons): Cons { + argumentValidator.validate(argumentList) + + val rest = argumentList.rest as Cons + val firstList = argumentList.first as Cons + val secondList = rest.first as Cons + + return appendLists(firstList, secondList) + } + + private fun appendLists(firstList: Cons, secondList: Cons): Cons { + firstListValidator.validate(firstList) + + if (firstList.isNull) + return secondList + + val appendedLists = copy(firstList) + appendedLists.last().rest = secondList + + return appendedLists + } + + private fun copy(list: Cons): Cons { + val newList = Cons(list.first, Nil) + var builder = newList + + list.asSequence().drop(1).forEach { + builder.rest = Cons(it.first, Nil) + builder = builder.rest as Cons + } + + return newList + } + + companion object { + + @JvmStatic + fun append(firstList: Cons, secondList: Cons): Cons { + return lookupAppend().appendLists(firstList, secondList) + } + + private fun lookupAppend() = FunctionTable.lookupFunction("APPEND") as Append + } +} diff --git a/src/main/kotlin/function/builtin/cons/CONS.java b/src/main/kotlin/function/builtin/cons/CONS.java deleted file mode 100644 index 3fcb453..0000000 --- a/src/main/kotlin/function/builtin/cons/CONS.java +++ /dev/null @@ -1,29 +0,0 @@ -package function.builtin.cons; - -import function.ArgumentValidator; -import function.FunctionNames; -import function.LispFunction; -import sexpression.Cons; -import sexpression.SExpression; - -@FunctionNames({ "CONS" }) -public class CONS extends LispFunction { - - private ArgumentValidator argumentValidator; - - public CONS(String name) { - this.argumentValidator = new ArgumentValidator(name); - this.argumentValidator.setExactNumberOfArguments(2); - } - - @Override - public Cons call(Cons argumentList) { - argumentValidator.validate(argumentList); - - Cons rest = (Cons) argumentList.getRest(); - SExpression firstArgument = argumentList.getFirst(); - SExpression secondArgument = rest.getFirst(); - - return new Cons(firstArgument, secondArgument); - } -} diff --git a/src/main/kotlin/function/builtin/cons/Construct.kt b/src/main/kotlin/function/builtin/cons/Construct.kt new file mode 100644 index 0000000..38fbe40 --- /dev/null +++ b/src/main/kotlin/function/builtin/cons/Construct.kt @@ -0,0 +1,24 @@ +package function.builtin.cons + +import function.ArgumentValidator +import function.FunctionNames +import function.LispFunction +import sexpression.Cons + +@FunctionNames("CONS") +class Construct(name: String) : LispFunction() { + + private val argumentValidator = ArgumentValidator(name).apply { + setExactNumberOfArguments(2) + } + + override fun call(argumentList: Cons): Cons { + argumentValidator.validate(argumentList) + + val rest = argumentList.rest as Cons + val firstArgument = argumentList.first + val secondArgument = rest.first + + return Cons(firstArgument, secondArgument) + } +} diff --git a/src/main/kotlin/function/builtin/cons/FIRST.java b/src/main/kotlin/function/builtin/cons/FIRST.java deleted file mode 100644 index f973ae5..0000000 --- a/src/main/kotlin/function/builtin/cons/FIRST.java +++ /dev/null @@ -1,27 +0,0 @@ -package function.builtin.cons; - -import function.ArgumentValidator; -import function.FunctionNames; -import function.LispFunction; -import sexpression.Cons; -import sexpression.SExpression; - -@FunctionNames({ "FIRST", "CAR" }) -public class FIRST extends LispFunction { - - private ArgumentValidator argumentValidator; - - public FIRST(String name) { - this.argumentValidator = new ArgumentValidator(name); - this.argumentValidator.setExactNumberOfArguments(1); - this.argumentValidator.setEveryArgumentExpectedType(Cons.class); - } - - @Override - public SExpression call(Cons argumentList) { - argumentValidator.validate(argumentList); - Cons argument = (Cons) argumentList.getFirst(); - - return argument.getFirst(); - } -} diff --git a/src/main/kotlin/function/builtin/cons/First.kt b/src/main/kotlin/function/builtin/cons/First.kt new file mode 100644 index 0000000..a58350d --- /dev/null +++ b/src/main/kotlin/function/builtin/cons/First.kt @@ -0,0 +1,23 @@ +package function.builtin.cons + +import function.ArgumentValidator +import function.FunctionNames +import function.LispFunction +import sexpression.Cons +import sexpression.SExpression + +@FunctionNames("FIRST", "CAR") +class First(name: String) : LispFunction() { + + private val argumentValidator = ArgumentValidator(name).apply { + setExactNumberOfArguments(1) + setEveryArgumentExpectedType(Cons::class.java) + } + + override fun call(argumentList: Cons): SExpression { + argumentValidator.validate(argumentList) + val argument = argumentList.first as Cons + + return argument.first + } +} diff --git a/src/main/kotlin/function/builtin/cons/LENGTH.java b/src/main/kotlin/function/builtin/cons/LENGTH.java deleted file mode 100644 index 86b9cb4..0000000 --- a/src/main/kotlin/function/builtin/cons/LENGTH.java +++ /dev/null @@ -1,65 +0,0 @@ -package function.builtin.cons; - -import function.ArgumentValidator; -import function.FunctionNames; -import function.LispFunction; -import recursion.TailCall; -import sexpression.Cons; -import sexpression.LispNumber; -import table.FunctionTable; - -import java.math.BigInteger; - -import static function.builtin.cons.LIST.makeList; -import static recursion.TailCalls.done; -import static recursion.TailCalls.tailCall; - -@FunctionNames({ "LENGTH" }) -public class LENGTH extends LispFunction { - - public static BigInteger getLength(Cons list) { - LispNumber length = lookupLength().callWithoutArgumentValidation(makeList(list)); - - return length.getValue(); - } - - private static LENGTH lookupLength() { - return (LENGTH) FunctionTable.INSTANCE.lookupFunction("LENGTH"); - } - - private ArgumentValidator argumentValidator; - private ArgumentValidator properListValidator; - - public LENGTH(String name) { - this.argumentValidator = new ArgumentValidator(name); - this.argumentValidator.setExactNumberOfArguments(1); - this.argumentValidator.setEveryArgumentExpectedType(Cons.class); - this.properListValidator = new ArgumentValidator(name + "|list|"); - } - - @Override - public LispNumber call(Cons argumentList) { - argumentValidator.validate(argumentList); - properListValidator.validate((Cons) argumentList.getFirst()); - - return callTailRecursive(BigInteger.ZERO, argumentList).invoke(); - } - - private LispNumber callWithoutArgumentValidation(Cons argumentList) { - return callTailRecursive(BigInteger.ZERO, argumentList).invoke(); - } - - private TailCall callTailRecursive(BigInteger accumulatedLength, Cons argumentList) { - Cons list = (Cons) argumentList.getFirst(); - Cons restOfList = makeList(list.getRest()); - - if (list.isNull()) - return done(new LispNumber(accumulatedLength)); - - return tailCall(() -> callTailRecursive(increment(accumulatedLength), restOfList)); - } - - private BigInteger increment(BigInteger number) { - return number.add(BigInteger.ONE); - } -} diff --git a/src/main/kotlin/function/builtin/cons/LIST.java b/src/main/kotlin/function/builtin/cons/LIST.java deleted file mode 100644 index 443d0f1..0000000 --- a/src/main/kotlin/function/builtin/cons/LIST.java +++ /dev/null @@ -1,29 +0,0 @@ -package function.builtin.cons; - -import function.ArgumentValidator; -import function.FunctionNames; -import function.LispFunction; -import sexpression.Cons; -import sexpression.Nil; -import sexpression.SExpression; - -@FunctionNames({ "LIST" }) -public class LIST extends LispFunction { - - public static Cons makeList(SExpression sexpr) { - return new Cons(sexpr, Nil.INSTANCE); - } - - private ArgumentValidator argumentValidator; - - public LIST(String name) { - this.argumentValidator = new ArgumentValidator(name); - } - - @Override - public Cons call(Cons argumentList) { - argumentValidator.validate(argumentList); - - return argumentList; - } -} diff --git a/src/main/kotlin/function/builtin/cons/Length.kt b/src/main/kotlin/function/builtin/cons/Length.kt new file mode 100644 index 0000000..c21d050 --- /dev/null +++ b/src/main/kotlin/function/builtin/cons/Length.kt @@ -0,0 +1,39 @@ +package function.builtin.cons + +import function.ArgumentValidator +import function.FunctionNames +import function.LispFunction +import sexpression.Cons +import sexpression.LispNumber +import table.FunctionTable +import table.FunctionTable.lookupFunction +import java.math.BigInteger.ZERO + +@FunctionNames("LENGTH") +class Length(name: String) : LispFunction() { + + private val argumentValidator = ArgumentValidator(name).apply { + setExactNumberOfArguments(1) + setEveryArgumentExpectedType(Cons::class.java) + } + + private val properListValidator = ArgumentValidator("$name|list|") + + override fun call(argumentList: Cons): LispNumber { + argumentValidator.validate(argumentList) + + val arguments = argumentList.first as Cons + properListValidator.validate(arguments) + + return getLength(arguments) + } + + private fun getLength(arguments: Cons) = + LispNumber(arguments.fold(ZERO) { count, _ -> count.inc() }) + + companion object { + + fun getLength(list: Cons) = lookupLength().getLength(list).value + private fun lookupLength() = lookupFunction("LENGTH") as Length + } +} diff --git a/src/main/kotlin/function/builtin/cons/List.kt b/src/main/kotlin/function/builtin/cons/List.kt new file mode 100644 index 0000000..aebbb1b --- /dev/null +++ b/src/main/kotlin/function/builtin/cons/List.kt @@ -0,0 +1,28 @@ +package function.builtin.cons + +import function.ArgumentValidator +import function.FunctionNames +import function.LispFunction +import sexpression.Cons +import sexpression.Nil +import sexpression.SExpression + +@FunctionNames("LIST") +class List(name: String) : LispFunction() { + + private val argumentValidator = ArgumentValidator(name) + + override fun call(argumentList: Cons): Cons { + argumentValidator.validate(argumentList) + + return argumentList + } + + companion object { + + @JvmStatic + fun makeList(sexpr: SExpression): Cons { + return Cons(sexpr, Nil) + } + } +} diff --git a/src/main/kotlin/function/builtin/cons/REST.java b/src/main/kotlin/function/builtin/cons/REST.java deleted file mode 100644 index e8e1142..0000000 --- a/src/main/kotlin/function/builtin/cons/REST.java +++ /dev/null @@ -1,27 +0,0 @@ -package function.builtin.cons; - -import function.ArgumentValidator; -import function.FunctionNames; -import function.LispFunction; -import sexpression.Cons; -import sexpression.SExpression; - -@FunctionNames({ "REST", "CDR" }) -public class REST extends LispFunction { - - private ArgumentValidator argumentValidator; - - public REST(String name) { - this.argumentValidator = new ArgumentValidator(name); - this.argumentValidator.setExactNumberOfArguments(1); - this.argumentValidator.setEveryArgumentExpectedType(Cons.class); - } - - @Override - public SExpression call(Cons argumentList) { - argumentValidator.validate(argumentList); - Cons argument = (Cons) argumentList.getFirst(); - - return argument.getRest(); - } -} diff --git a/src/main/kotlin/function/builtin/cons/Rest.kt b/src/main/kotlin/function/builtin/cons/Rest.kt new file mode 100644 index 0000000..3a4408e --- /dev/null +++ b/src/main/kotlin/function/builtin/cons/Rest.kt @@ -0,0 +1,23 @@ +package function.builtin.cons + +import function.ArgumentValidator +import function.FunctionNames +import function.LispFunction +import sexpression.Cons +import sexpression.SExpression + +@FunctionNames("REST", "CDR") +class Rest(name: String) : LispFunction() { + + private val argumentValidator = ArgumentValidator(name).apply { + setExactNumberOfArguments(1) + setEveryArgumentExpectedType(Cons::class.java) + } + + override fun call(argumentList: Cons): SExpression { + argumentValidator.validate(argumentList) + val argument = argumentList.first as Cons + + return argument.rest + } +} diff --git a/src/main/kotlin/function/builtin/math/DIVIDE.java b/src/main/kotlin/function/builtin/math/DIVIDE.java deleted file mode 100644 index 7c63391..0000000 --- a/src/main/kotlin/function/builtin/math/DIVIDE.java +++ /dev/null @@ -1,53 +0,0 @@ -package function.builtin.math; - -import error.LispException; -import function.ArgumentValidator; -import function.FunctionNames; -import function.LispFunction; -import sexpression.Cons; -import sexpression.LispNumber; - -import java.math.BigInteger; - -@FunctionNames({ "/" }) -public class DIVIDE extends LispFunction { - - private ArgumentValidator argumentValidator; - private MathFunction mathFunction; - - public DIVIDE(String name) { - this.argumentValidator = new ArgumentValidator(name); - this.argumentValidator.setMinimumNumberOfArguments(1); - this.argumentValidator.setEveryArgumentExpectedType(LispNumber.class); - this.mathFunction = new MathFunction(this::getReciprocal, this::divide); - } - - @Override - public LispNumber call(Cons argumentList) { - argumentValidator.validate(argumentList); - - try { - return mathFunction.callTailRecursive(argumentList).invoke(); - } catch (ArithmeticException e) { - throw new DivideByZeroException(); - } - } - - private LispNumber getReciprocal(LispNumber number) { - return new LispNumber(BigInteger.ONE.divide(number.getValue())); - } - - private LispNumber divide(LispNumber number1, LispNumber number2) { - return new LispNumber(number1.getValue().divide(number2.getValue())); - } - - public static class DivideByZeroException extends LispException { - - private static final long serialVersionUID = 1L; - - @Override - public String getMessage() { - return "divide by zero"; - } - } -} diff --git a/src/main/kotlin/function/builtin/math/Divide.kt b/src/main/kotlin/function/builtin/math/Divide.kt new file mode 100644 index 0000000..d571e5b --- /dev/null +++ b/src/main/kotlin/function/builtin/math/Divide.kt @@ -0,0 +1,41 @@ +package function.builtin.math + +import error.LispException +import function.ArgumentValidator +import function.FunctionNames +import function.LispFunction +import sexpression.Cons +import sexpression.LispNumber +import java.math.BigInteger.ONE + +@FunctionNames("/") +class Divide(name: String) : LispFunction() { + + private val argumentValidator = ArgumentValidator(name).apply { + setMinimumNumberOfArguments(1) + setEveryArgumentExpectedType(LispNumber::class.java) + } + + private val mathFunction = MathFunction(this::getReciprocal, this::divide) + + override fun call(argumentList: Cons): LispNumber { + argumentValidator.validate(argumentList) + + try { + return mathFunction.callTailRecursive(argumentList) + } catch (e: ArithmeticException) { + throw DivideByZeroException() + } + } + + private fun getReciprocal(number: LispNumber) = + LispNumber(ONE / number.value) + + private fun divide(number1: LispNumber, number2: LispNumber) = + LispNumber(number1.value / number2.value) + + class DivideByZeroException : LispException() { + + override val message = "divide by zero" + } +} diff --git a/src/main/kotlin/function/builtin/math/MINUS.java b/src/main/kotlin/function/builtin/math/MINUS.java deleted file mode 100644 index 44e655f..0000000 --- a/src/main/kotlin/function/builtin/math/MINUS.java +++ /dev/null @@ -1,38 +0,0 @@ -package function.builtin.math; - -import function.ArgumentValidator; -import function.FunctionNames; -import function.LispFunction; -import sexpression.Cons; -import sexpression.LispNumber; - -import java.math.BigInteger; - -@FunctionNames({ "-" }) -public class MINUS extends LispFunction { - - private ArgumentValidator argumentValidator; - private MathFunction mathFunction; - - public MINUS(String name) { - this.argumentValidator = new ArgumentValidator(name); - this.argumentValidator.setMinimumNumberOfArguments(1); - this.argumentValidator.setEveryArgumentExpectedType(LispNumber.class); - this.mathFunction = new MathFunction(this::additiveInverse, this::subtract); - } - - @Override - public LispNumber call(Cons argumentList) { - argumentValidator.validate(argumentList); - - return mathFunction.callTailRecursive(argumentList).invoke(); - } - - private LispNumber additiveInverse(LispNumber number) { - return new LispNumber(BigInteger.ZERO.subtract(number.getValue())); - } - - private LispNumber subtract(LispNumber number1, LispNumber number2) { - return new LispNumber(number1.getValue().subtract(number2.getValue())); - } -} diff --git a/src/main/kotlin/function/builtin/math/MODULO.java b/src/main/kotlin/function/builtin/math/MODULO.java deleted file mode 100644 index e612b70..0000000 --- a/src/main/kotlin/function/builtin/math/MODULO.java +++ /dev/null @@ -1,44 +0,0 @@ -package function.builtin.math; - -import error.LispException; -import function.ArgumentValidator; -import function.FunctionNames; -import function.LispFunction; -import sexpression.Cons; -import sexpression.LispNumber; -import sexpression.SExpression; - -@FunctionNames({ "MOD", "MODULO", "%" }) -public class MODULO extends LispFunction { - - private ArgumentValidator argumentValidator; - - public MODULO(String name) { - this.argumentValidator = new ArgumentValidator(name); - this.argumentValidator.setExactNumberOfArguments(2); - this.argumentValidator.setEveryArgumentExpectedType(LispNumber.class); - } - - @Override - public SExpression call(Cons argumentList) { - argumentValidator.validate(argumentList); - LispNumber dividend = (LispNumber) argumentList.getFirst(); - LispNumber divisor = (LispNumber) ((Cons) argumentList.getRest()).getFirst(); - - try { - return new LispNumber(dividend.getValue().mod(divisor.getValue())); - } catch (ArithmeticException e) { - throw new ModulusNotPositiveException(); - } - } - - public static class ModulusNotPositiveException extends LispException { - - private static final long serialVersionUID = 1L; - - @Override - public String getMessage() { - return "modulus not positive"; - } - } -} diff --git a/src/main/kotlin/function/builtin/math/MULTIPLY.java b/src/main/kotlin/function/builtin/math/MULTIPLY.java deleted file mode 100644 index 5420fd5..0000000 --- a/src/main/kotlin/function/builtin/math/MULTIPLY.java +++ /dev/null @@ -1,31 +0,0 @@ -package function.builtin.math; - -import function.ArgumentValidator; -import function.FunctionNames; -import function.LispFunction; -import sexpression.Cons; -import sexpression.LispNumber; - -@FunctionNames({ "*" }) -public class MULTIPLY extends LispFunction { - - private ArgumentValidator argumentValidator; - private MathFunction mathFunction; - - public MULTIPLY(String name) { - this.argumentValidator = new ArgumentValidator(name); - this.argumentValidator.setEveryArgumentExpectedType(LispNumber.class); - this.mathFunction = new MathFunction(number -> number, this::multiply); - } - - @Override - public LispNumber call(Cons argumentList) { - argumentValidator.validate(argumentList); - - return mathFunction.callTailRecursive(new Cons(LispNumber.Companion.getONE(), argumentList)).invoke(); - } - - private LispNumber multiply(LispNumber number1, LispNumber number2) { - return new LispNumber(number1.getValue().multiply(number2.getValue())); - } -} diff --git a/src/main/kotlin/function/builtin/math/MathFunction.java b/src/main/kotlin/function/builtin/math/MathFunction.java deleted file mode 100644 index fcd8500..0000000 --- a/src/main/kotlin/function/builtin/math/MathFunction.java +++ /dev/null @@ -1,43 +0,0 @@ -package function.builtin.math; - -import recursion.TailCall; -import sexpression.Cons; -import sexpression.LispNumber; -import sexpression.SExpression; - -import java.util.function.BiFunction; -import java.util.function.Function; - -import static recursion.TailCalls.done; -import static recursion.TailCalls.tailCall; - -class MathFunction { - - Function singleValueOperation; - BiFunction multipleValueOperation; - - public MathFunction(Function singleValueOperation, - BiFunction multipleValueOperation) { - this.singleValueOperation = singleValueOperation; - this.multipleValueOperation = multipleValueOperation; - } - - public TailCall callTailRecursive(Cons argumentList) { - Cons remainingArguments = (Cons) argumentList.getRest(); - SExpression firstArgument = argumentList.getFirst(); - LispNumber number1 = (LispNumber) firstArgument; - - if (remainingArguments.isNull()) - return done(singleValueOperation.apply(number1)); - - SExpression secondArgument = remainingArguments.getFirst(); - LispNumber number2 = (LispNumber) secondArgument; - LispNumber operationResult = multipleValueOperation.apply(number1, number2); - SExpression remainingNumbers = remainingArguments.getRest(); - - if (remainingNumbers.isNull()) - return done(operationResult); - - return tailCall(() -> callTailRecursive(new Cons(operationResult, remainingNumbers))); - } -} diff --git a/src/main/kotlin/function/builtin/math/MathFunction.kt b/src/main/kotlin/function/builtin/math/MathFunction.kt new file mode 100644 index 0000000..01ca262 --- /dev/null +++ b/src/main/kotlin/function/builtin/math/MathFunction.kt @@ -0,0 +1,27 @@ +package function.builtin.math + +import sexpression.Cons +import sexpression.LispNumber + +internal class MathFunction(private val singleValueOperation: (LispNumber) -> LispNumber, + private val multipleValueOperation: (LispNumber, LispNumber) -> LispNumber) { + + tailrec fun callTailRecursive(argumentList: Cons): LispNumber { + val remainingArguments = argumentList.rest as Cons + val firstArgument = argumentList.first + val number1 = firstArgument as LispNumber + + if (remainingArguments.isNull) + return singleValueOperation(number1) + + val secondArgument = remainingArguments.first + val number2 = secondArgument as LispNumber + val operationResult = multipleValueOperation(number1, number2) + val remainingNumbers = remainingArguments.rest + + return if (remainingNumbers.isNull) + operationResult + else + callTailRecursive(Cons(operationResult, remainingNumbers)) + } +} diff --git a/src/main/kotlin/function/builtin/math/Minus.kt b/src/main/kotlin/function/builtin/math/Minus.kt new file mode 100644 index 0000000..30cfc4d --- /dev/null +++ b/src/main/kotlin/function/builtin/math/Minus.kt @@ -0,0 +1,32 @@ +package function.builtin.math + +import function.ArgumentValidator +import function.FunctionNames +import function.LispFunction +import sexpression.Cons +import sexpression.LispNumber + +import java.math.BigInteger.ZERO + +@FunctionNames("-") +class Minus(name: String) : LispFunction() { + + private val argumentValidator = ArgumentValidator(name).apply { + setMinimumNumberOfArguments(1) + setEveryArgumentExpectedType(LispNumber::class.java) + } + + private val mathFunction: MathFunction = MathFunction(this::additiveInverse, this::subtract) + + override fun call(argumentList: Cons): LispNumber { + argumentValidator.validate(argumentList) + + return mathFunction.callTailRecursive(argumentList) + } + + private fun additiveInverse(number: LispNumber) = + LispNumber(ZERO - number.value) + + private fun subtract(number1: LispNumber, number2: LispNumber) = + LispNumber(number1.value - number2.value) +} diff --git a/src/main/kotlin/function/builtin/math/Module.kt b/src/main/kotlin/function/builtin/math/Module.kt new file mode 100644 index 0000000..518376a --- /dev/null +++ b/src/main/kotlin/function/builtin/math/Module.kt @@ -0,0 +1,36 @@ +package function.builtin.math + +import error.LispException +import function.ArgumentValidator +import function.FunctionNames +import function.LispFunction +import sexpression.Cons +import sexpression.LispNumber +import sexpression.SExpression + +@FunctionNames("MOD", "MODULO", "%") +class Module(name: String) : LispFunction() { + + private val argumentValidator = ArgumentValidator(name).apply { + setExactNumberOfArguments(2) + setEveryArgumentExpectedType(LispNumber::class.java) + } + + override fun call(argumentList: Cons): SExpression { + argumentValidator.validate(argumentList) + + val dividend = argumentList.first as LispNumber + val divisor = (argumentList.rest as Cons).first as LispNumber + + try { + return LispNumber(dividend.value.mod(divisor.value)) + } catch (e: ArithmeticException) { + throw ModulusNotPositiveException() + } + } + + class ModulusNotPositiveException : LispException() { + + override val message = "modulus not positive" + } +} diff --git a/src/main/kotlin/function/builtin/math/Multiply.kt b/src/main/kotlin/function/builtin/math/Multiply.kt new file mode 100644 index 0000000..000b218 --- /dev/null +++ b/src/main/kotlin/function/builtin/math/Multiply.kt @@ -0,0 +1,27 @@ +package function.builtin.math + +import function.ArgumentValidator +import function.FunctionNames +import function.LispFunction +import sexpression.Cons +import sexpression.LispNumber +import sexpression.LispNumber.Companion.ONE + +@FunctionNames("*") +class Multiply(name: String) : LispFunction() { + + private val argumentValidator = ArgumentValidator(name).apply { + setEveryArgumentExpectedType(LispNumber::class.java) + } + + private val mathFunction: MathFunction = MathFunction({ it }, this::multiply) + + override fun call(argumentList: Cons): LispNumber { + argumentValidator.validate(argumentList) + + return mathFunction.callTailRecursive(Cons(ONE, argumentList)) + } + + private fun multiply(number1: LispNumber, number2: LispNumber) = + LispNumber(number1.value * number2.value) +} diff --git a/src/main/kotlin/function/builtin/math/PLUS.java b/src/main/kotlin/function/builtin/math/PLUS.java deleted file mode 100644 index 40a1eae..0000000 --- a/src/main/kotlin/function/builtin/math/PLUS.java +++ /dev/null @@ -1,31 +0,0 @@ -package function.builtin.math; - -import function.ArgumentValidator; -import function.FunctionNames; -import function.LispFunction; -import sexpression.Cons; -import sexpression.LispNumber; - -@FunctionNames({ "+" }) -public class PLUS extends LispFunction { - - private ArgumentValidator argumentValidator; - private MathFunction mathFunction; - - public PLUS(String name) { - this.argumentValidator = new ArgumentValidator(name); - this.argumentValidator.setEveryArgumentExpectedType(LispNumber.class); - this.mathFunction = new MathFunction(number -> number, this::add); - } - - @Override - public LispNumber call(Cons argumentList) { - argumentValidator.validate(argumentList); - - return mathFunction.callTailRecursive(new Cons(LispNumber.Companion.getZERO(), argumentList)).invoke(); - } - - private LispNumber add(LispNumber number1, LispNumber number2) { - return new LispNumber(number1.getValue().add(number2.getValue())); - } -} diff --git a/src/main/kotlin/function/builtin/math/Plus.kt b/src/main/kotlin/function/builtin/math/Plus.kt new file mode 100644 index 0000000..cc277fa --- /dev/null +++ b/src/main/kotlin/function/builtin/math/Plus.kt @@ -0,0 +1,26 @@ +package function.builtin.math + +import function.ArgumentValidator +import function.FunctionNames +import function.LispFunction +import sexpression.Cons +import sexpression.LispNumber + +@FunctionNames("+") +class Plus(name: String) : LispFunction() { + + private val argumentValidator = ArgumentValidator(name).apply { + setEveryArgumentExpectedType(LispNumber::class.java) + } + + private val mathFunction: MathFunction = MathFunction({ it }, this::add) + + override fun call(argumentList: Cons): LispNumber { + argumentValidator.validate(argumentList) + + return mathFunction.callTailRecursive(Cons(LispNumber.ZERO, argumentList)) + } + + private fun add(number1: LispNumber, number2: LispNumber) = + LispNumber(number1.value + number2.value) +} diff --git a/src/main/kotlin/function/builtin/math/REMAINDER.java b/src/main/kotlin/function/builtin/math/REMAINDER.java deleted file mode 100644 index f1a367c..0000000 --- a/src/main/kotlin/function/builtin/math/REMAINDER.java +++ /dev/null @@ -1,34 +0,0 @@ -package function.builtin.math; - -import function.ArgumentValidator; -import function.FunctionNames; -import function.LispFunction; -import function.builtin.math.DIVIDE.DivideByZeroException; -import sexpression.Cons; -import sexpression.LispNumber; -import sexpression.SExpression; - -@FunctionNames({ "REM", "REMAINDER" }) -public class REMAINDER extends LispFunction { - - private ArgumentValidator argumentValidator; - - public REMAINDER(String name) { - this.argumentValidator = new ArgumentValidator(name); - this.argumentValidator.setExactNumberOfArguments(2); - this.argumentValidator.setEveryArgumentExpectedType(LispNumber.class); - } - - @Override - public SExpression call(Cons argumentList) { - argumentValidator.validate(argumentList); - LispNumber dividend = (LispNumber) argumentList.getFirst(); - LispNumber divisor = (LispNumber) ((Cons) argumentList.getRest()).getFirst(); - - try { - return new LispNumber(dividend.getValue().remainder(divisor.getValue())); - } catch (ArithmeticException e) { - throw new DivideByZeroException(); - } - } -} diff --git a/src/main/kotlin/function/builtin/math/Remainder.kt b/src/main/kotlin/function/builtin/math/Remainder.kt new file mode 100644 index 0000000..2393a5d --- /dev/null +++ b/src/main/kotlin/function/builtin/math/Remainder.kt @@ -0,0 +1,31 @@ +package function.builtin.math + +import function.ArgumentValidator +import function.FunctionNames +import function.LispFunction +import function.builtin.math.Divide.DivideByZeroException +import sexpression.Cons +import sexpression.LispNumber +import sexpression.SExpression + +@FunctionNames("REM", "REMAINDER") +class Remainder(name: String) : LispFunction() { + + private val argumentValidator = ArgumentValidator(name).apply { + setExactNumberOfArguments(2) + setEveryArgumentExpectedType(LispNumber::class.java) + } + + override fun call(argumentList: Cons): SExpression { + argumentValidator.validate(argumentList) + + val dividend = argumentList.first as LispNumber + val divisor = (argumentList.rest as Cons).first as LispNumber + + try { + return LispNumber(dividend.value % divisor.value) + } catch (e: ArithmeticException) { + throw DivideByZeroException() + } + } +} diff --git a/src/main/kotlin/function/builtin/predicate/NumericLess.kt b/src/main/kotlin/function/builtin/predicate/NumericLess.kt index 35fc8fd..487d059 100644 --- a/src/main/kotlin/function/builtin/predicate/NumericLess.kt +++ b/src/main/kotlin/function/builtin/predicate/NumericLess.kt @@ -3,14 +3,10 @@ package function.builtin.predicate import function.ArgumentValidator import function.FunctionNames import function.LispFunction -import recursion.TailCall import sexpression.Cons import sexpression.LispNumber import sexpression.Nil import sexpression.SExpression - -import recursion.TailCalls.done -import recursion.TailCalls.tailCall import sexpression.Symbol.Companion.T @FunctionNames("<") @@ -39,7 +35,7 @@ class NumericLess(name: String) : LispFunction() { val number2 = secondArgument as LispNumber return if (number1.value < number2.value) - callTailRecursive(remainingArguments) + callTailRecursive(remainingArguments) else Nil } diff --git a/src/main/kotlin/function/builtin/special/Define.kt b/src/main/kotlin/function/builtin/special/Define.kt index 5fc23bf..4d794e7 100644 --- a/src/main/kotlin/function/builtin/special/Define.kt +++ b/src/main/kotlin/function/builtin/special/Define.kt @@ -5,7 +5,7 @@ import error.LispWarning import function.ArgumentValidator import function.LispSpecialFunction import function.UserDefinedFunction -import function.builtin.cons.LIST.makeList +import function.builtin.cons.List.Companion.makeList import sexpression.Cons import sexpression.SExpression import sexpression.Symbol diff --git a/src/main/kotlin/function/builtin/special/DefineSpecial.kt b/src/main/kotlin/function/builtin/special/DefineSpecial.kt index 8c82cfd..61913ed 100644 --- a/src/main/kotlin/function/builtin/special/DefineSpecial.kt +++ b/src/main/kotlin/function/builtin/special/DefineSpecial.kt @@ -1,7 +1,6 @@ package function.builtin.special import function.FunctionNames -import function.UserDefinedFunction import function.UserDefinedSpecialFunction import sexpression.Cons import sexpression.SExpression diff --git a/src/main/kotlin/function/builtin/special/Defmacro.kt b/src/main/kotlin/function/builtin/special/Defmacro.kt index aec6402..771de1e 100644 --- a/src/main/kotlin/function/builtin/special/Defmacro.kt +++ b/src/main/kotlin/function/builtin/special/Defmacro.kt @@ -1,7 +1,6 @@ package function.builtin.special import function.FunctionNames -import function.UserDefinedFunction import function.UserDefinedMacro import sexpression.Cons import sexpression.SExpression diff --git a/src/main/kotlin/function/builtin/special/Lambda.kt b/src/main/kotlin/function/builtin/special/Lambda.kt index 91aa6ea..767b7e1 100644 --- a/src/main/kotlin/function/builtin/special/Lambda.kt +++ b/src/main/kotlin/function/builtin/special/Lambda.kt @@ -4,7 +4,7 @@ import function.ArgumentValidator import function.FunctionNames import function.LispSpecialFunction import function.UserDefinedFunction -import function.builtin.cons.LIST.makeList +import function.builtin.cons.List.Companion.makeList import sexpression.Cons import sexpression.LambdaExpression import sexpression.SExpression diff --git a/src/main/kotlin/function/builtin/special/Setq.kt b/src/main/kotlin/function/builtin/special/Setq.kt index 48b41cb..c9b9bef 100644 --- a/src/main/kotlin/function/builtin/special/Setq.kt +++ b/src/main/kotlin/function/builtin/special/Setq.kt @@ -5,7 +5,7 @@ import function.FunctionNames import function.LispSpecialFunction import function.builtin.Eval.Companion.eval import function.builtin.Set.Companion.set -import function.builtin.cons.LIST.makeList +import function.builtin.cons.List.Companion.makeList import sexpression.Cons import sexpression.SExpression import sexpression.Symbol diff --git a/src/main/kotlin/table/SymbolTable.kt b/src/main/kotlin/table/SymbolTable.kt index 41e9a14..a0a1910 100644 --- a/src/main/kotlin/table/SymbolTable.kt +++ b/src/main/kotlin/table/SymbolTable.kt @@ -1,7 +1,7 @@ package table -import function.builtin.cons.APPEND.append -import function.builtin.cons.LIST.makeList +import function.builtin.cons.Append.Companion.append +import function.builtin.cons.List.Companion.makeList import sexpression.Cons import sexpression.Nil import sexpression.SExpression diff --git a/src/test/kotlin/function/builtin/cons/APPENDTest.java b/src/test/kotlin/function/builtin/cons/AppendTest.java similarity index 97% rename from src/test/kotlin/function/builtin/cons/APPENDTest.java rename to src/test/kotlin/function/builtin/cons/AppendTest.java index 5378fec..5a39d28 100644 --- a/src/test/kotlin/function/builtin/cons/APPENDTest.java +++ b/src/test/kotlin/function/builtin/cons/AppendTest.java @@ -11,7 +11,7 @@ import static testutil.TestUtilities.assertSExpressionsMatch; import static testutil.TestUtilities.evaluateString; import static testutil.TestUtilities.parseString; -public class APPENDTest extends SymbolAndFunctionCleaner { +public class AppendTest extends SymbolAndFunctionCleaner { @Test public void appendNil() { diff --git a/src/test/kotlin/function/builtin/cons/CONSTest.java b/src/test/kotlin/function/builtin/cons/ConstructTest.java similarity index 96% rename from src/test/kotlin/function/builtin/cons/CONSTest.java rename to src/test/kotlin/function/builtin/cons/ConstructTest.java index 53a7b63..2044669 100644 --- a/src/test/kotlin/function/builtin/cons/CONSTest.java +++ b/src/test/kotlin/function/builtin/cons/ConstructTest.java @@ -11,7 +11,7 @@ import static testutil.TestUtilities.assertSExpressionsMatch; import static testutil.TestUtilities.evaluateString; import static testutil.TestUtilities.parseString; -public class CONSTest extends SymbolAndFunctionCleaner { +public class ConstructTest extends SymbolAndFunctionCleaner { @Test public void consWithNilValues() { diff --git a/src/test/kotlin/function/builtin/cons/FIRSTTest.java b/src/test/kotlin/function/builtin/cons/FirstTest.java similarity index 96% rename from src/test/kotlin/function/builtin/cons/FIRSTTest.java rename to src/test/kotlin/function/builtin/cons/FirstTest.java index c509634..21c72f1 100644 --- a/src/test/kotlin/function/builtin/cons/FIRSTTest.java +++ b/src/test/kotlin/function/builtin/cons/FirstTest.java @@ -10,7 +10,7 @@ import static testutil.TestUtilities.assertSExpressionsMatch; import static testutil.TestUtilities.evaluateString; import static testutil.TestUtilities.parseString; -public class FIRSTTest extends SymbolAndFunctionCleaner { +public class FirstTest extends SymbolAndFunctionCleaner { @Test public void firstOfNil() { diff --git a/src/test/kotlin/function/builtin/cons/LENGTHTest.java b/src/test/kotlin/function/builtin/cons/LengthTest.java similarity index 96% rename from src/test/kotlin/function/builtin/cons/LENGTHTest.java rename to src/test/kotlin/function/builtin/cons/LengthTest.java index 0668a38..2194975 100644 --- a/src/test/kotlin/function/builtin/cons/LENGTHTest.java +++ b/src/test/kotlin/function/builtin/cons/LengthTest.java @@ -11,7 +11,7 @@ import static testutil.TestUtilities.assertSExpressionsMatch; import static testutil.TestUtilities.evaluateString; import static testutil.TestUtilities.parseString; -public class LENGTHTest extends SymbolAndFunctionCleaner { +public class LengthTest extends SymbolAndFunctionCleaner { @Test public void lengthOfNil() { diff --git a/src/test/kotlin/function/builtin/cons/LISTTest.java b/src/test/kotlin/function/builtin/cons/ListTest.java similarity index 93% rename from src/test/kotlin/function/builtin/cons/LISTTest.java rename to src/test/kotlin/function/builtin/cons/ListTest.java index b869eee..6dccf3b 100644 --- a/src/test/kotlin/function/builtin/cons/LISTTest.java +++ b/src/test/kotlin/function/builtin/cons/ListTest.java @@ -3,12 +3,12 @@ package function.builtin.cons; import org.junit.Test; import testutil.SymbolAndFunctionCleaner; -import static function.builtin.cons.LIST.makeList; +import static function.builtin.cons.List.makeList; import static testutil.TestUtilities.assertSExpressionsMatch; import static testutil.TestUtilities.evaluateString; import static testutil.TestUtilities.parseString; -public class LISTTest extends SymbolAndFunctionCleaner { +public class ListTest extends SymbolAndFunctionCleaner { @Test public void listWithNoArguments() { diff --git a/src/test/kotlin/function/builtin/cons/RESTTest.java b/src/test/kotlin/function/builtin/cons/RestTest.java similarity index 96% rename from src/test/kotlin/function/builtin/cons/RESTTest.java rename to src/test/kotlin/function/builtin/cons/RestTest.java index 46c70d6..eb21906 100644 --- a/src/test/kotlin/function/builtin/cons/RESTTest.java +++ b/src/test/kotlin/function/builtin/cons/RestTest.java @@ -10,7 +10,7 @@ import static testutil.TestUtilities.assertSExpressionsMatch; import static testutil.TestUtilities.evaluateString; import static testutil.TestUtilities.parseString; -public class RESTTest extends SymbolAndFunctionCleaner { +public class RestTest extends SymbolAndFunctionCleaner { @Test public void restOfNil() { diff --git a/src/test/kotlin/function/builtin/math/DIVIDETest.java b/src/test/kotlin/function/builtin/math/DivideTest.java similarity index 94% rename from src/test/kotlin/function/builtin/math/DIVIDETest.java rename to src/test/kotlin/function/builtin/math/DivideTest.java index f27409a..258099d 100644 --- a/src/test/kotlin/function/builtin/math/DIVIDETest.java +++ b/src/test/kotlin/function/builtin/math/DivideTest.java @@ -2,7 +2,7 @@ package function.builtin.math; import function.ArgumentValidator.BadArgumentTypeException; import function.ArgumentValidator.TooFewArgumentsException; -import function.builtin.math.DIVIDE.DivideByZeroException; +import function.builtin.math.Divide.DivideByZeroException; import org.junit.Test; import testutil.SymbolAndFunctionCleaner; @@ -11,7 +11,7 @@ import static testutil.TestUtilities.assertSExpressionsMatch; import static testutil.TestUtilities.evaluateString; import static testutil.TestUtilities.parseString; -public class DIVIDETest extends SymbolAndFunctionCleaner { +public class DivideTest extends SymbolAndFunctionCleaner { @Test public void divideWithOne() { diff --git a/src/test/kotlin/function/builtin/math/MINUSTest.java b/src/test/kotlin/function/builtin/math/MinusTest.java similarity index 95% rename from src/test/kotlin/function/builtin/math/MINUSTest.java rename to src/test/kotlin/function/builtin/math/MinusTest.java index 6c350e1..63352d1 100644 --- a/src/test/kotlin/function/builtin/math/MINUSTest.java +++ b/src/test/kotlin/function/builtin/math/MinusTest.java @@ -9,7 +9,7 @@ import testutil.SymbolAndFunctionCleaner; import static testutil.TestUtilities.assertSExpressionsMatch; import static testutil.TestUtilities.evaluateString; -public class MINUSTest extends SymbolAndFunctionCleaner { +public class MinusTest extends SymbolAndFunctionCleaner { @Test public void minusWithOneNumber() { diff --git a/src/test/kotlin/function/builtin/math/MODULOTest.java b/src/test/kotlin/function/builtin/math/ModuleTest.java similarity index 96% rename from src/test/kotlin/function/builtin/math/MODULOTest.java rename to src/test/kotlin/function/builtin/math/ModuleTest.java index 83f4df7..1b67c77 100644 --- a/src/test/kotlin/function/builtin/math/MODULOTest.java +++ b/src/test/kotlin/function/builtin/math/ModuleTest.java @@ -3,7 +3,7 @@ package function.builtin.math; import function.ArgumentValidator.BadArgumentTypeException; import function.ArgumentValidator.TooFewArgumentsException; import function.ArgumentValidator.TooManyArgumentsException; -import function.builtin.math.MODULO.ModulusNotPositiveException; +import function.builtin.math.Module.ModulusNotPositiveException; import org.junit.Test; import sexpression.LispNumber; import testutil.SymbolAndFunctionCleaner; @@ -12,7 +12,7 @@ import static testutil.TestUtilities.assertIsErrorWithMessage; import static testutil.TestUtilities.assertSExpressionsMatch; import static testutil.TestUtilities.evaluateString; -public class MODULOTest extends SymbolAndFunctionCleaner { +public class ModuleTest extends SymbolAndFunctionCleaner { @Test public void mod() { diff --git a/src/test/kotlin/function/builtin/math/MULTIPLYTest.java b/src/test/kotlin/function/builtin/math/MultiplyTest.java similarity index 95% rename from src/test/kotlin/function/builtin/math/MULTIPLYTest.java rename to src/test/kotlin/function/builtin/math/MultiplyTest.java index d6cd2c9..01375fe 100644 --- a/src/test/kotlin/function/builtin/math/MULTIPLYTest.java +++ b/src/test/kotlin/function/builtin/math/MultiplyTest.java @@ -8,7 +8,7 @@ import testutil.SymbolAndFunctionCleaner; import static testutil.TestUtilities.assertSExpressionsMatch; import static testutil.TestUtilities.evaluateString; -public class MULTIPLYTest extends SymbolAndFunctionCleaner { +public class MultiplyTest extends SymbolAndFunctionCleaner { @Test public void multiplyWithNoArguments() { diff --git a/src/test/kotlin/function/builtin/math/PLUSTest.java b/src/test/kotlin/function/builtin/math/PlusTest.java similarity index 95% rename from src/test/kotlin/function/builtin/math/PLUSTest.java rename to src/test/kotlin/function/builtin/math/PlusTest.java index 9e297dc..f2d5193 100644 --- a/src/test/kotlin/function/builtin/math/PLUSTest.java +++ b/src/test/kotlin/function/builtin/math/PlusTest.java @@ -8,7 +8,7 @@ import testutil.SymbolAndFunctionCleaner; import static testutil.TestUtilities.assertSExpressionsMatch; import static testutil.TestUtilities.evaluateString; -public class PLUSTest extends SymbolAndFunctionCleaner { +public class PlusTest extends SymbolAndFunctionCleaner { @Test public void plusWithNoArguments() { diff --git a/src/test/kotlin/function/builtin/math/REMAINDERTest.java b/src/test/kotlin/function/builtin/math/RemainderTest.java similarity index 95% rename from src/test/kotlin/function/builtin/math/REMAINDERTest.java rename to src/test/kotlin/function/builtin/math/RemainderTest.java index 0573267..effb586 100644 --- a/src/test/kotlin/function/builtin/math/REMAINDERTest.java +++ b/src/test/kotlin/function/builtin/math/RemainderTest.java @@ -3,7 +3,7 @@ package function.builtin.math; import function.ArgumentValidator.BadArgumentTypeException; import function.ArgumentValidator.TooFewArgumentsException; import function.ArgumentValidator.TooManyArgumentsException; -import function.builtin.math.DIVIDE.DivideByZeroException; +import function.builtin.math.Divide.DivideByZeroException; import org.junit.Test; import sexpression.LispNumber; import testutil.SymbolAndFunctionCleaner; @@ -11,7 +11,7 @@ import testutil.SymbolAndFunctionCleaner; import static testutil.TestUtilities.assertSExpressionsMatch; import static testutil.TestUtilities.evaluateString; -public class REMAINDERTest extends SymbolAndFunctionCleaner { +public class RemainderTest extends SymbolAndFunctionCleaner { @Test public void rem() {