JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in
# from https://janet.guide/control-flow/ (defn calculate [expr] (match expr [:add x y] (+ x y) [:subtract x y] (- x y) [:multiply x y] (* x y) ([:divide x y] (= y 0)) (error "division by zero!") [:divide x y] (/ x y))) (calculate [:subtract 5 10]) # Note, it checks prefixes, so you must order things this way: (match [1 2] [x y z] "three elements" [x y] "two elements" [x] "one element" [] "no elements")