OSDN Git Service

dup
authorsforman <sforman@hushmail.com>
Sat, 29 Jul 2023 16:22:26 +0000 (09:22 -0700)
committersforman <sforman@hushmail.com>
Sat, 29 Jul 2023 16:22:26 +0000 (09:22 -0700)
implementations/Elm/src/Joy.elm

index da79796..c25b8aa 100644 (file)
@@ -45,6 +45,7 @@ joy_eval symbol stack expression =
         "clear" -> Ok ([], expression)
         "concat" -> joy_concat stack expression
         "cons" -> joy_cons stack expression
+        "dup" -> joy_dup stack expression
         _ -> Err ("Unknown word: " ++ symbol)
 
 
@@ -80,6 +81,12 @@ joy_cons stack expression =
         Err msg -> Err msg
 
 
+joy_dup : JList -> JList -> Result String (JList, JList)
+joy_dup stack expression =
+    case pop_any(stack) of
+        Ok (a, s0) -> Ok ((a :: stack), expression)
+        Err msg -> Err msg
+
 
 push_int : Int -> JList -> JList
 push_int i stack = (JoyInt i) :: stack