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.
75 lines
3.1 KiB
Plaintext
75 lines
3.1 KiB
Plaintext
;;;; raylib [text] example - text writing anim
|
|
;;;;
|
|
;;;; examples/text/text_writing_anim.c. Sixty lines of C whose whole substance
|
|
;;;; is one call this package cannot bind:
|
|
;;;;
|
|
;;;; DrawText(TextSubtext(message, 0, framesCounter/10), ...)
|
|
;;;;
|
|
;;;; TextSubtext is in raylib.h and is not in the bindings, on the rule
|
|
;;;; raylib.flan states for the whole Text* family: it answers a `char *` into
|
|
;;;; a rotating static buffer, and declare-c refuses a returned pointer to
|
|
;;;; memory the caller does not own. There is no missing line to add — the
|
|
;;;; binding would be wrong at any signature.
|
|
;;;;
|
|
;;;; And it does not matter, because Flan has the operation as a primitive.
|
|
;;;; `(slice a lo hi)` takes a view of an array, `(string b)` reinterprets the
|
|
;;;; bytes as a string at no cost, and `(string (slice message 0 n))` is
|
|
;;;; TextSubtext with the static buffer removed — no copy, no shared state, no
|
|
;;;; rotation to run out of. Porting the example is therefore how the gap gets
|
|
;;;; *closed* rather than reported: the C's workaround for not having slices
|
|
;;;; is the thing Flan did not need.
|
|
;;;;
|
|
;;;; The one place they differ, and it is why the clamp below is here rather
|
|
;;;; than in the C: TextSubtext clips its length to the string, so the C can
|
|
;;;; pass a counter that runs past the end for ever and see nothing happen.
|
|
;;;; `slice` does not clip — an out-of-range bound is an error, and a bound
|
|
;;;; computed at run time is checked at run time — so the length has to be
|
|
;;;; brought inside the string before the call. That is a better failure than
|
|
;;;; the C's, and it costs one `min`.
|
|
;;;;
|
|
;;;; The message is a `[u8]` and not a `string` because `slice` takes an array
|
|
;;;; or a slice; `(bytes-view "…")` is the bridge in the other direction from
|
|
;;;; `(string …)` and costs nothing either. The embedded newline is written as
|
|
;;;; an escape, and raylib's draw-text breaks the line on it.
|
|
|
|
(import rl "vendor:raylib")
|
|
|
|
(defconst screen-width 800)
|
|
(defconst screen-height 450)
|
|
|
|
(defconst message
|
|
"This sample illustrates a text writing\nanimation effect! Check it out! ;)")
|
|
|
|
(defonce frames-counter i32)
|
|
|
|
(defn main [] ()
|
|
(rl/init-window screen-width screen-height
|
|
"raylib [text] example - text writing anim")
|
|
(defer (rl/close-window))
|
|
|
|
(set frames-counter 0)
|
|
|
|
(rl/set-target-fps 60)
|
|
|
|
(until (rl/window-should-close?)
|
|
;; Update. Holding space runs the counter eight times faster; enter starts
|
|
;; it over.
|
|
(if (rl/key-down? :key-space)
|
|
(set frames-counter (+ frames-counter 8))
|
|
(set frames-counter (+ frames-counter 1)))
|
|
|
|
(when (rl/key-pressed? :key-enter) (set frames-counter 0))
|
|
|
|
;; Draw
|
|
(rl/with-drawing
|
|
(rl/clear-background rl/raywhite)
|
|
|
|
;; One character every ten frames. The clamp is the whole difference from
|
|
;; the C — see the header comment.
|
|
(let [b (bytes-view message)
|
|
n (min (i32 (length b)) (/ frames-counter 10))]
|
|
(rl/draw-text (string (slice b 0 n)) 210 160 20 rl/maroon))
|
|
|
|
(rl/draw-text "PRESS [ENTER] to RESTART!" 240 260 20 rl/lightgray)
|
|
(rl/draw-text "HOLD [SPACE] to SPEED UP!" 239 300 20 rl/lightgray))))
|