;;;; = and != on bools, a match over a bool, and keyword arms over a dyn. (defstruct Flag [on bool]) (defn truth [n i32] bool (> n 0)) (defn is-same [a bool b bool] bool (= a b)) ;; Exhaustive without a _ arm: true and false are every bool. (defn word [b bool] str (match b true "yes" false "no")) (defn flipped [b bool] i32 (match b false 0 true 1)) (defn only-true [b bool] i32 (match b true 1 _ 0)) ;; Over a dyn :north is the arm (= d :north), beside numbers, strings and ;; bools, which are dyn values too. (defn heading [d dyn] str (match d :north "up" :south "down" 1 "one" "west" "left" true "true" _ "other")) (defn main [] i32 (let [f (Flag {.on true}) g (Flag {.on false}) flags [true false true]] (print (is-same true true)) (print " ") (print (is-same true false)) (print " ") (print (!= true false)) (print " ") (print (= (.on f) (truth 3))) (print " ") (print (= (.on g) (truth 3))) (print " ") (print (!= (.on g) (at flags 1))) (print " ") (print (= true (at flags 0) (at flags 2))) (println "") (println (word true)) (println (word (truth -1))) (print (flipped true)) (print (flipped false)) (print (only-true true)) (print (only-true false)) (println "") (println (heading :north)) (println (heading :south)) (println (heading :east)) (println (heading 1.0)) (println (heading "west")) (println (heading true)) (println (heading false)) 0))