diff --git a/src/main/java/com/vectron/fcl/Fcl.java b/src/main/java/com/vectron/fcl/Fcl.java index 5142745..028ffb4 100644 --- a/src/main/java/com/vectron/fcl/Fcl.java +++ b/src/main/java/com/vectron/fcl/Fcl.java @@ -368,6 +368,7 @@ public class Fcl { addPrimitive("var:", () -> { String name = word(); dict.add(new Var(dp, name)); dp++; }); addPrimitive("val:", () -> { String name = word(); dict.add(new Val(name, stack.pop())); }); addPrimitive("abort", () -> { throw new Aborted(stack.pop().asStr().value()); }); + addPrimitive("eval", () -> eval(stack.pop().asStr().value())); addPrimitive("words", () -> { List words = new ArrayList(wordList()); Collections.sort(words); diff --git a/src/test/java/com/vectron/fcl/FclTest.java b/src/test/java/com/vectron/fcl/FclTest.java index 35680d6..352910c 100644 --- a/src/test/java/com/vectron/fcl/FclTest.java +++ b/src/test/java/com/vectron/fcl/FclTest.java @@ -1133,6 +1133,12 @@ public class FclTest { assertEquals("#[ ]#", evalPop("12 hist").toString()); } + @Test + public void testEval() { + assertEquals(3, evalPop(" '1 2 +' eval").intValue()); + assertEquals(42, evalPop(" ': tst 42 ; tst' eval").intValue()); + } + private String transcript() { return transcript.content(); }