diff --git a/.idea/ClojureProjectResolveSettings.xml b/.idea/ClojureProjectResolveSettings.xml
new file mode 100644
index 0000000..df470b1
--- /dev/null
+++ b/.idea/ClojureProjectResolveSettings.xml
@@ -0,0 +1,6 @@
+
+
+
+ IDE
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index a2d49a1..6f0bc46 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -18,6 +18,17 @@
+
+
+
+
+
+
+
+
+
@@ -60,5 +71,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
index 79ee123..940db4f 100644
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index f32c555..0e0b4d2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,10 +8,12 @@
transcendental-lisp
1.2.0
-
-
-
+
+ UTF-8
+ 1.2.30
+
+
org.apache.maven.plugins
@@ -25,10 +27,61 @@
3.0.2
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+ 1.8
+
+
+
org.apache.maven.plugins
maven-compiler-plugin
3.7.0
+
+
+
+ default-compile
+ none
+
+
+
+ default-testCompile
+ none
+
+
+ java-compile
+ compile
+
+ compile
+
+
+
+ java-test-compile
+ test-compile
+
+ testCompile
+
+
+
1.8
@@ -79,12 +132,25 @@
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-jdk8
+ ${kotlin.version}
+
+
com.googlecode.lanterna
lanterna
3.0.0
+
+ org.jetbrains.kotlin
+ kotlin-test
+ ${kotlin.version}
+ test
+
+
junit
junit
@@ -114,8 +180,4 @@
-
- UTF-8
-
-
\ No newline at end of file
diff --git a/src/main/java/function/builtin/EVAL.java b/src/main/java/function/builtin/EVAL.java
index fb56914..0a2d576 100644
--- a/src/main/java/function/builtin/EVAL.java
+++ b/src/main/java/function/builtin/EVAL.java
@@ -4,6 +4,7 @@ import error.LispException;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
+import function.builtin.special.LAMBDA;
import function.builtin.special.RECUR.RecurNotInTailPositionException;
import sexpression.BackquoteExpression;
import sexpression.Cons;
@@ -13,8 +14,6 @@ import sexpression.Symbol;
import table.ExecutionContext;
import static function.builtin.cons.LIST.makeList;
-import static function.builtin.special.LAMBDA.createFunction;
-import static function.builtin.special.LAMBDA.isLambdaExpression;
import static java.text.MessageFormat.format;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
@@ -60,8 +59,8 @@ public class EVAL extends LispFunction {
private static LispFunction createLambdaFunction(SExpression lambdaExpression) {
if (lambdaExpression.isFunction())
return ((LambdaExpression) lambdaExpression).getFunction();
- else if (isLambdaExpression(lambdaExpression))
- return createFunction((Cons) lambdaExpression);
+ else if (LAMBDA.Companion.isLambdaExpression(lambdaExpression))
+ return LAMBDA.Companion.createFunction((Cons) lambdaExpression);
else
throw new UndefinedFunctionException(lambdaExpression);
}
diff --git a/src/main/java/function/builtin/special/LAMBDA.java b/src/main/java/function/builtin/special/LAMBDA.java
deleted file mode 100644
index f4f70a3..0000000
--- a/src/main/java/function/builtin/special/LAMBDA.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package function.builtin.special;
-
-import function.ArgumentValidator;
-import function.FunctionNames;
-import function.LispSpecialFunction;
-import function.UserDefinedFunction;
-import sexpression.Cons;
-import sexpression.LambdaExpression;
-import sexpression.SExpression;
-import sexpression.Symbol;
-
-import static function.builtin.cons.LIST.makeList;
-
-@FunctionNames({ "LAMBDA", "Λ" })
-public class LAMBDA extends LispSpecialFunction {
-
- public static boolean isLambdaExpression(SExpression sexpr) {
- if (sexpr.isCons()) {
- String first = ((Cons) sexpr).getFirst().toString();
-
- return "LAMBDA".equals(first) || "Λ".equals(first);
- }
-
- return false;
- }
-
- public static UserDefinedFunction createFunction(Cons lambdaExpression) {
- SExpression rest = lambdaExpression.getRest();
-
- ArgumentValidator lambdaValidator = new ArgumentValidator("LAMBDA|create|");
- lambdaValidator.setEveryArgumentExpectedType(Cons.class);
- lambdaValidator.validate(makeList(rest));
-
- LambdaExpression lambda = new LAMBDA("LAMBDA").call((Cons) rest);
-
- return lambda.getFunction();
- }
-
- private ArgumentValidator argumentValidator;
- private ArgumentValidator lambdaListValidator;
-
- public LAMBDA(String name) {
- this.argumentValidator = new ArgumentValidator(name);
- this.argumentValidator.setFirstArgumentExpectedType(Cons.class);
- this.argumentValidator.setMinimumNumberOfArguments(1);
-
- this.lambdaListValidator = new ArgumentValidator(name + "|lambda-list|");
- this.lambdaListValidator.setEveryArgumentExpectedType(Symbol.class);
- }
-
- @Override
- public LambdaExpression call(Cons argumentList) {
- argumentValidator.validate(argumentList);
-
- SExpression first = argumentList.getFirst();
- Cons lambdaList = (Cons) first;
- Cons body = (Cons) argumentList.getRest();
-
- lambdaListValidator.validate(lambdaList);
-
- UserDefinedFunction function = new UserDefinedFunction(":LAMBDA", lambdaList, body);
-
- return new LambdaExpression(makeOriginalLambdaExpression(argumentList), function);
- }
-
- private Cons makeOriginalLambdaExpression(Cons argumentList) {
- return new Cons(new Symbol("LAMBDA"), argumentList);
- }
-}
diff --git a/src/main/java/function/builtin/special/LAMBDA.kt b/src/main/java/function/builtin/special/LAMBDA.kt
new file mode 100644
index 0000000..262e995
--- /dev/null
+++ b/src/main/java/function/builtin/special/LAMBDA.kt
@@ -0,0 +1,68 @@
+package function.builtin.special
+
+import function.ArgumentValidator
+import function.FunctionNames
+import function.LispSpecialFunction
+import function.UserDefinedFunction
+import function.builtin.cons.LIST.makeList
+import sexpression.Cons
+import sexpression.LambdaExpression
+import sexpression.SExpression
+import sexpression.Symbol
+
+@FunctionNames("LAMBDA", "Λ")
+class LAMBDA(name: String) : LispSpecialFunction() {
+
+
+ private val argumentValidator: ArgumentValidator = ArgumentValidator(name)
+ private val lambdaListValidator: ArgumentValidator = ArgumentValidator("$name|lambda-list|")
+
+ init {
+ this.argumentValidator.setFirstArgumentExpectedType(Cons::class.java)
+ this.argumentValidator.setMinimumNumberOfArguments(1)
+ this.lambdaListValidator.setEveryArgumentExpectedType(Symbol::class.java)
+ }
+
+ override fun call(argumentList: Cons): LambdaExpression {
+ argumentValidator.validate(argumentList)
+
+ val first = argumentList.first
+ val lambdaList = first as Cons
+ val body = argumentList.rest as Cons
+
+ lambdaListValidator.validate(lambdaList)
+
+ val function = UserDefinedFunction(":LAMBDA", lambdaList, body)
+
+ return LambdaExpression(makeOriginalLambdaExpression(argumentList), function)
+ }
+
+ private fun makeOriginalLambdaExpression(argumentList: Cons): Cons {
+ return Cons(Symbol("LAMBDA"), argumentList)
+ }
+
+ companion object {
+
+ fun isLambdaExpression(sexpr: SExpression): Boolean {
+ if (sexpr.isCons) {
+ val first = (sexpr as Cons).first.toString()
+
+ return "LAMBDA" == first || "Λ" == first
+ }
+
+ return false
+ }
+
+ fun createFunction(lambdaExpression: Cons): UserDefinedFunction {
+ val rest = lambdaExpression.rest
+
+ val lambdaValidator = ArgumentValidator("LAMBDA|create|")
+ lambdaValidator.setEveryArgumentExpectedType(Cons::class.java)
+ lambdaValidator.validate(makeList(rest))
+
+ val lambda = LAMBDA("LAMBDA").call(rest as Cons)
+
+ return lambda.function
+ }
+ }
+}
diff --git a/src/test/java/function/builtin/special/LAMBDATest.java b/src/test/java/function/builtin/special/LAMBDATest.java
index 539793d..d36a56d 100644
--- a/src/test/java/function/builtin/special/LAMBDATest.java
+++ b/src/test/java/function/builtin/special/LAMBDATest.java
@@ -47,12 +47,12 @@ public class LAMBDATest extends SymbolAndFunctionCleaner {
public void lambdaExpressionIsLambdaExpression() {
Cons lambdaExpression = new Cons(new Symbol("LAMBDA"), new Cons(NIL, new Cons(NIL, NIL)));
- assertTrue(LAMBDA.isLambdaExpression(lambdaExpression));
+ assertTrue(LAMBDA.Companion.isLambdaExpression(lambdaExpression));
}
@Test
public void somethingElseIsNotLambdaExpression() {
- assertFalse(LAMBDA.isLambdaExpression(T));
+ assertFalse(LAMBDA.Companion.isLambdaExpression(T));
}
@Test
@@ -60,7 +60,7 @@ public class LAMBDATest extends SymbolAndFunctionCleaner {
Cons lambdaExpression = new Cons(new Symbol("LAMBDA"), new Cons(NIL, new Cons(NIL, NIL)));
assertSExpressionsMatch(parseString("(:LAMBDA () ())"),
- LAMBDA.createFunction(lambdaExpression).getLambdaExpression());
+ LAMBDA.Companion.createFunction(lambdaExpression).getLambdaExpression());
}
@Test(expected = DottedArgumentListException.class)
@@ -81,14 +81,14 @@ public class LAMBDATest extends SymbolAndFunctionCleaner {
public void createFunctionWithDottedArgumentList() {
Cons lambdaExpression = new Cons(new Symbol("LAMBDA"), new Cons(NIL, ONE));
- LAMBDA.createFunction(lambdaExpression);
+ LAMBDA.Companion.createFunction(lambdaExpression);
}
@Test(expected = BadArgumentTypeException.class)
public void createFunctionWithNonList() {
Cons lambdaExpression = new Cons(new Symbol("LAMBDA"), ONE);
- LAMBDA.createFunction(lambdaExpression);
+ LAMBDA.Companion.createFunction(lambdaExpression);
}
@Test(expected = BadArgumentTypeException.class)