;;;; 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))