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.
14 lines
473 B
Plaintext
14 lines
473 B
Plaintext
(defconst nums [4 i32] [4 8 15 16])
|
|
|
|
;; `some` unwraps Some and early-returns None from *this* function.
|
|
(defn doubled-first [s [i32]] (Option i32)
|
|
(Some (* 2 (some (index-of-i32 s 15)))))
|
|
|
|
(defn main []
|
|
(match (doubled-first (slice nums 0 4))
|
|
(Some i) (do (print-i64 (i64 i)) (newline)) ; 4
|
|
None (print-line "not found"))
|
|
(match (index-of-i32 (slice nums 0 4) 99)
|
|
(Some i) (do (print-i64 (i64 i)) (newline))
|
|
None (print-line "not found")))
|