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.
34 lines
1.4 KiB
Plaintext
34 lines
1.4 KiB
Plaintext
;;;; A package whose exports are generic.
|
|
;;;;
|
|
;;;; The spike's "no plan" bucket named this one, and named what makes it
|
|
;;;; work: Load flattens every import into one namespace *before* the checker
|
|
;;;; runs, so the generic's body is present at the call site the way a C++
|
|
;;;; template's is because it sits in a header. Nothing here crosses a real
|
|
;;;; compilation-unit boundary, and the day a package becomes one, this is the
|
|
;;;; thing that has to change — a copy is made from a body, and a body that
|
|
;;;; did not cross cannot be copied.
|
|
;;;;
|
|
;;;; What this package is for: a generic called from the program at two types,
|
|
;;;; a bounded generic whose {:where} has to be readable from outside the
|
|
;;;; file that wrote it, and a generic that calls another generic in its own
|
|
;;;; package at its own variable, so the transitive copy is generated from a
|
|
;;;; call site two files away.
|
|
|
|
(defn last-of [s [$t]] $t
|
|
(at s (- (length s) 1)))
|
|
|
|
;;; Calls last-of at its own variable: the copy of last-of is generated when
|
|
;;; this is instantiated, and this is instantiated from the program.
|
|
(defn ends [s [$t]] $t
|
|
(last-of s))
|
|
|
|
;;; The bound travels with the signature. A caller that passes a type the
|
|
;;; clause refuses is refused at the call, against a requirement written in
|
|
;;; another file.
|
|
(defn largest [s [$t]] $t
|
|
{:where (ordered? $t)}
|
|
(let [m (at s 0)]
|
|
(dotimes [i (length s)]
|
|
(set m (max m (at s i))))
|
|
m))
|