diff --git a/src/main/java/com/vectron/fcl/types/Dic.java b/src/main/java/com/vectron/fcl/types/Dic.java index 174cc3b..2b0eabf 100644 --- a/src/main/java/com/vectron/fcl/types/Dic.java +++ b/src/main/java/com/vectron/fcl/types/Dic.java @@ -1,5 +1,6 @@ package com.vectron.fcl.types; +import com.vectron.fcl.exceptions.Aborted; import com.vectron.fcl.exceptions.TypeMismatched; import java.util.Iterator; @@ -82,6 +83,13 @@ public class Dic implements Obj { this.value.put(key, value); } + public void append(Obj lst) { + if (lst instanceof Lst && ((Lst)lst).size() == 2) + this.value.put(((Lst)lst).at(new Num(0)), ((Lst)lst).at(new Num(1))); + else + throw new Aborted("Expected list of size 2 when adding to a map, got: " + lst); + } + public Obj at(Obj key) { return value.get(key); } diff --git a/src/test/java/com/vectron/fcl/FclTest.java b/src/test/java/com/vectron/fcl/FclTest.java index e85f287..35680d6 100644 --- a/src/test/java/com/vectron/fcl/FclTest.java +++ b/src/test/java/com/vectron/fcl/FclTest.java @@ -782,6 +782,7 @@ public class FclTest { assertEquals(3, evalPop("m size").intValue()); assertEquals(1, evalPop("m 'a' at").intValue()); assertEquals("b", evalPop("m 2 at").asStr().value()); + assertEquals("#[ 'x' 'y' ]#", evalPop(" dup [ 'x' 'y' ] add").toString()); assertEquals(false, evalPop("m true at").boolValue()); assertEquals(Nil.INSTANCE, evalPop("m 'nosuch' at")); assertEquals(0, evalPop("m clear m size").intValue());