Copying a snippet into HTML is where a documented language stops being the real one. Each block on the page is a program here with its recorded output beside it, and check.sh is what says the page is still true after a change.
31 lines
688 B
Plaintext
31 lines
688 B
Plaintext
(defconst nums [5 i32] [1 3 8 9 10])
|
|
|
|
(defn classify [n i32] string
|
|
(cond
|
|
(< n 0) "negative"
|
|
(= n 0) "zero"
|
|
:else "positive"))
|
|
|
|
(defn countdown [n i32]
|
|
(let [i n]
|
|
(while (> i 0)
|
|
(print-i64 (i64 i))
|
|
(print-str " ")
|
|
(set i (- i 1)))
|
|
(newline)))
|
|
|
|
(defn first-even [s [i32]] (Option i32)
|
|
(dotimes [i (len s)]
|
|
(when (= 0 (% (at s i) 2))
|
|
(return (Some (at s i)))))
|
|
None)
|
|
|
|
(defn main []
|
|
(print-line (classify -3))
|
|
(countdown 4)
|
|
(unless false
|
|
(print-line "unless runs when the test is false"))
|
|
(match (first-even (slice nums 0 (len nums)))
|
|
(Some n) (do (print-i64 (i64 n)) (newline))
|
|
None (print-line "none")))
|