flan/test/programs/reload-generic.flan
Joseph Ferano a0f37e72a2 The ! suffix retires: a mutator is named for what it does, not marked
The !-means-mutates convention distinguished nothing — there is no
immutable counterpart to contrast with — so every mutating name drops
the mark: sort, sort-by, sort-bytes, swap, reverse, append, append-i64,
append-f64, encode-rune, split-next, map-remove, map-next, and the test
helpers beside them. Two could not simply shed it: map! is map-in-place,
because map is the into transform's word and means the non-mutating
thing; put! is put-at, because put is the Map builtin. The ?-means-asks
convention stays. Dated records keep the old spellings; watch.clj's
reset-spies! and the other Clojure names are not ours to rename.
2026-09-19 05:21:02 +07:00

38 lines
1.2 KiB
Plaintext

;;;; The session's fixture for generics in the dev loop.
;;;;
;;;; A generic [defn] never reaches [Tast.fns] — only its copies do — so every
;;;; question the editor asks about one has to be answered by expanding the
;;;; name. This file is the smallest program that makes each of those
;;;; questions concrete: one generic used at two element types, one generic
;;;; that calls another so that instantiation has to be transitive, and one
;;;; call site whose element type is *not* used anywhere else, so that a
;;;; redefinition can reach a copy the process was never built with.
(defvar counter i64)
(defn put-at [xs [$t] i i32 v $t] ()
(set (at xs i) v))
;;; Calls [put-at] at its own variable, so the copy of [put-at] is generated when
;;; [hold] is instantiated and not before.
(defn hold [xs [$t] v $t] ()
(put-at xs 0 v))
(defn pick [xs [$t]] $t
{:where (ordered? $t)}
(let [m (at xs 0)]
(dotimes [i (len xs)]
(set m (min m (at xs i))))
m))
(defn step [] ()
(let [ns [5 3 9 1]
fs [2.5 0.5 1.5]]
(hold (slice ns 0 4) 7)
(hold (slice fs 0 3) 0.25)
(set counter (+ counter (i64 (pick (slice ns 0 4)))))))
(defn main [] ()
(step)
(println counter))