swap!, reverse!, sort!, sort-by!, index-of, min-of, max-of, map!, reduce and filter, each written once over $t. Every call site in the corpus moves with them. min-of and max-of are not min and max because min and max are builtins over two or more numbers and nothing shadows a builtin. These reduce a slice, which is a different operation at a different arity. sort-bytes! did not collapse into sort!, and the reason is the point of the predicates: a [u8] is not ordered? and cannot be, because < is an instruction and comparing two slices lexicographically is a loop. It is sort-by! with bytes<? written in, one line, keeping its name and its stability note. sum-i32/sum-f32 and append-i64!/append-f64! stay for the reasons the spike gave. Not what the notes predicted: none of the ten collapses on a signature change alone. filter and reduce need copyable? because the checker demands it - reduce's accumulator at (Vec i32) is a double move - and the rest declare it because a slice of owning elements would have them duplicating headers.
14 lines
455 B
Plaintext
14 lines
455 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 s 15)))))
|
|
|
|
(defn main [] ()
|
|
(match (doubled-first (slice nums 0 4))
|
|
(Some i) (do (print i) (println "")) ; 4
|
|
None (println "not found"))
|
|
(match (index-of (slice nums 0 4) 99)
|
|
(Some i) (do (print i) (println ""))
|
|
None (println "not found")))
|