flan/test/programs/len-bound.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.5 KiB
Plaintext

;;;; `len` as an ordinary name, which is the whole reason the count is spelled
;;;; `length`.
;;;;
;;;; Shadowing already made a `(defn len ...)` legal, and `builtin/len` already
;;;; made the builtin reachable past one. What is left, and what this file is,
;;;; is that `len` is not a builtin at all: nothing warns, nothing needs the
;;;; qualifier, and the name is free in every position a name can be in. A
;;;; global called `len` is the one case that cannot also be here — this is a
;;;; Lisp-1 and a defn and a defonce may not share a name — so it is pinned in
;;;; test_flan instead. `len-gone.flan` is the other half: the call to the name
;;;; nothing defines.
;;;;
;;;; Four lines. In order: the local (3), the parameter doubled (6), the defn
;;;; reached by its bare name (2), and the local again over a Vec (3).
(defn twice-len [len i32] i32
(* len 2))
;;; A defn takes the name too, and a call to it is this program's. Nothing is
;;; shadowed here — if `len` were still a builtin this definition would carry
;;; a warning, and shadow-builtin.flan is where that sentence is pinned.
(defn len [s [i32]] i32
(length s))
(defn main [] ()
(let [xs [10 20 30]]
;; The shape the long word exists for: the count in a binding called len.
(let [len (length xs)]
(println len)
(println (twice-len len)))
;; And the bare name as a call, where no local has taken it.
(println (len (slice xs 0 2))))
(let [v (vec-new i32)]
(push v 1) (push v 2) (push v 3)
(let [len (length v)]
(println len))
(free v)))