flan/test/programs/reload-generic.flan
Joseph Ferano d6fc15474b The count is length, so len is a name a program can have
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.
2026-09-21 11:58:56 +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.
(defonce 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 (length 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))