The author: "I think I prefer length over len, because then I'll use len as the variable name". One arm in check.ml, one row in the table beside it, and every (len x) in lib, test, examples, vendor, spike, docs, web, emacs, plan.org and NEXT.md rewritten. Shadowing and builtin/ had already taken most of the sting out: a (defn len ...) was legal and won in its own file, and builtin/len reached past it. What was left is that len was still a builtin — the defn earned a warning, and a wrapper had to say builtin/ at every inner call. Now there is nothing under the short name: len is an ordinary identifier in every position, which is what (let [len (length xs)] ...) wants. length takes over as shadowing's worked example rather than the feature losing one. shadow-builtin.flan, builtin-qualified.flan, pkgs/shadowed and the builtin/ rows in test_flan move to it and go on testing shadowing. A call to a len nothing defines is answered where an unknown function is, after every table and after the shadowing guard, so a program with its own len never reaches it. The sentence is said rather than guessed at — len and length are three edits apart and the did-you-mean's net is one — and the call is written back out through spell_arg, as-slice's spelling lifted out of it and now shared, so what is printed compiles. sand.flan:33 still calls the old name and is the author's to change; until it does, test_acceptance and test_session abort there. Both were run green against a copy with that one line changed. FIX.org says so.
52 lines
1.4 KiB
Plaintext
52 lines
1.4 KiB
Plaintext
;; Which of prelude.ml's per-type families collapse as they are written, and
|
|
;; which need their signature changed. Nothing here is installed in the
|
|
;; prelude; it is the same bodies, over $t, checked and run.
|
|
|
|
(defn keep [s [$t] keep? (Fn [$t] bool)] (Vec $t)
|
|
(let [v (vec-new t)]
|
|
(dotimes [i (length s)]
|
|
(when (keep? (at s i))
|
|
(push v (at s i))))
|
|
v))
|
|
|
|
(defn apply! [s [$t] f (Fn [$t] $t)] ()
|
|
(dotimes [i (length s)]
|
|
(set (at s i) (f (at s i)))))
|
|
|
|
(defn fold [s [$t] init $t f (Fn [$t $t] $t)] t
|
|
(let [acc init]
|
|
(dotimes [i (length s)]
|
|
(set acc (f acc (at s i))))
|
|
acc))
|
|
|
|
(defn flip! [s [$t]] ()
|
|
(let [i 0
|
|
j (- (length s) 1)]
|
|
(while (< i j)
|
|
(let [tmp (at s i)]
|
|
(set (at s i) (at s j))
|
|
(set (at s j) tmp))
|
|
(set i (+ i 1))
|
|
(set j (- j 1)))))
|
|
|
|
(defonce ns [5 i32])
|
|
(defonce fs [5 f32])
|
|
|
|
(defn main [] ()
|
|
(let [xs (slice ns 0 5)
|
|
ys (slice fs 0 5)]
|
|
(dotimes [i 5]
|
|
(set (at xs i) (+ i 1))
|
|
(set (at ys i) (f32 (* 2 (+ i 1)))))
|
|
(apply! xs (fn [x] (* x 10)))
|
|
(apply! ys (fn [x] (* x (f32 2))))
|
|
(flip! xs)
|
|
(flip! ys)
|
|
(println (fold xs 0 (fn [a b] (+ a b))))
|
|
(println (fold ys (f32 0) (fn [a b] (+ a b))))
|
|
(let [evens (keep xs (fn [x] (= (% x 20) 0)))]
|
|
(println (length evens))
|
|
(free evens))
|
|
(println (at xs 0))
|
|
(println (at ys 0))))
|