OSDN Git Service

Logical ops.
authorsforman <sforman@hushmail.com>
Sat, 29 Jul 2023 18:37:07 +0000 (11:37 -0700)
committersforman <sforman@hushmail.com>
Sat, 29 Jul 2023 18:37:07 +0000 (11:37 -0700)
implementations/Elm/src/Joy.elm

index 7c0da9c..717bc3c 100644 (file)
@@ -62,6 +62,10 @@ joy_eval symbol stack expression =
         "rshift" -> joy_binary_math_op (swap_args Bitwise.shiftRightBy) stack expression
         ">>" -> joy_binary_math_op (swap_args Bitwise.shiftRightBy) stack expression
 
+        "/\\" -> joy_logical_op (&&) stack expression
+        "\\/" -> joy_logical_op (||) stack expression
+        "_\\/_" -> joy_logical_op (xor) stack expression
+
         "clear" -> Ok ([], expression)
         "concat" -> joy_concat stack expression
         "cons" -> joy_cons stack expression
@@ -151,6 +155,17 @@ joy_comparison_op op stack expression =
         Err msg -> Err msg
 
 
+joy_logical_op : (Bool -> Bool -> Bool) -> JList -> JList -> Result String (JList, JList)
+joy_logical_op op stack expression =
+    case pop_bool(stack) of
+        Ok (a, s0) ->
+            case pop_bool(s0) of
+                Ok (b, s1) ->
+                    Ok ((push_bool (op b a) s1), expression)
+                Err msg -> Err msg
+        Err msg -> Err msg
+
+
 joy_concat : JList -> JList -> Result String (JList, JList)
 joy_concat stack expression =
     case pop_list(stack) of