OSDN Git Service

stack, swaack
authorsforman <sforman@hushmail.com>
Sat, 29 Jul 2023 17:00:16 +0000 (10:00 -0700)
committersforman <sforman@hushmail.com>
Sat, 29 Jul 2023 17:00:16 +0000 (10:00 -0700)
implementations/Elm/src/Joy.elm

index 42c3e52..91a4340 100644 (file)
@@ -49,6 +49,8 @@ joy_eval symbol stack expression =
         "first" -> joy_first stack expression
         "pop" -> joy_pop stack expression
         "rest" -> joy_rest stack expression
+        "stack" -> joy_stack stack expression
+        "swaack" -> joy_swaack stack expression
         _ -> Err ("Unknown word: " ++ symbol)
 
 
@@ -118,6 +120,18 @@ joy_rest stack expression =
         Err msg -> Err msg
 
 
+joy_stack : JList -> JList -> Result String (JList, JList)
+joy_stack stack expression =
+    Ok ((push_list stack stack), expression)
+
+
+joy_swaack : JList -> JList -> Result String (JList, JList)
+joy_swaack stack expression =
+    case pop_list(stack) of
+        Ok (s, s0) -> Ok ((push_list s0 s), expression)
+        Err msg -> Err msg
+
+
 push_int : Int -> JList -> JList
 push_int i stack = (JoyInt i) :: stack