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.
39 lines
1.6 KiB
Plaintext
39 lines
1.6 KiB
Plaintext
;;;; (bytes s) copies, (bytes-view s) aliases — the ruling from the
|
|
;;;; INSERTIONSORT dogfooding session. The pin is the exact inverse of the
|
|
;;;; old aliasing: a write through the copy leaves the original string
|
|
;;;; printing unchanged, where the old (bytes s) either showed the write
|
|
;;;; through or trapped, depending on where the string's storage was.
|
|
|
|
(defonce frame Allocator)
|
|
|
|
(defn main [] i32
|
|
;; 1. The copy is writable and independent. Under the old reinterpret this
|
|
;; second line printed ZNSERTIONSORT too (or the whole program died in
|
|
;; .rodata) — the original staying itself is the whole of the change.
|
|
(let [s "INSERTIONSORT"
|
|
b (bytes s)]
|
|
(set (at b 0) \Z)
|
|
(println (string b)) ; ZNSERTIONSORT
|
|
(println s)) ; INSERTIONSORT
|
|
|
|
;; 2. A literal's copy is writable — the exact form that used to segfault
|
|
;; at -O0 and silently do nothing at -O2.
|
|
(let [b (bytes "hi")]
|
|
(set (at b 0) \H)
|
|
(println (string b))) ; Hi
|
|
|
|
;; 3. The view still costs nothing and reads the string's own storage.
|
|
(let [v (bytes-view "abc")]
|
|
(println (length v)) ; 3
|
|
(println (at v 2))) ; 99
|
|
|
|
;; 4. (bytes s a) names the allocator, like (vec-new T a) and (clone v a):
|
|
;; the copy's block comes from the arena and free-all reclaims it.
|
|
(set frame (arena-new 4096))
|
|
(let [b (bytes "arena" frame)]
|
|
(set (at b 4) \A)
|
|
(println (string b))) ; arenA
|
|
(free-all frame)
|
|
(arena-destroy frame)
|
|
0)
|