slovo/examples/boolean-logic.slo
2026-05-22 08:38:43 +02:00

59 lines
907 B
Plaintext

(module main)
(fn and_true () -> bool
(and true true))
(fn and_false () -> bool
(and true false))
(fn or_true () -> bool
(or false true))
(fn not_false () -> bool
(not false))
(fn and_short_circuits () -> bool
(not (and false (= (/ 1 0) 0))))
(fn or_short_circuits () -> bool
(or true (= (/ 1 0) 0)))
(fn logic_ok () -> bool
(if (and_true)
(if (not (and_false))
(if (or_true)
(if (not_false)
(if (and_short_circuits)
(or_short_circuits)
false)
false)
false)
false)
false))
(fn main () -> i32
(if (logic_ok)
42
1))
(test "and true"
(and_true))
(test "and false"
(not (and_false)))
(test "or true"
(or_true))
(test "not false"
(not_false))
(test "and short circuit"
(and_short_circuits))
(test "or short circuit"
(or_short_circuits))
(test "boolean logic summary"
(logic_ok))