flan/test/programs/agent-queue.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

44 lines
1.8 KiB
Plaintext

;;;; The job ring between the listener thread and the game thread, and what it
;;;; does when it is full.
;;;;
;;;; The window this needs is "the listener has queued modules the game thread
;;;; has not looked at yet", and that window has to be held open by something
;;;; other than a timer — how long sixty-five connections take on a loaded
;;;; machine is exactly the kind of race a test must not be. So the program
;;;; blocks on stdin: the test fills the ring, checks what the agent said, and
;;;; only then writes the byte that lets the program poll.
(import agent "vendor:agent")
;;; libc's, declared straight: no aggregate crosses the boundary, so there is
;;; nothing for a shim to do.
(declare stdin-byte [] i32 "getchar")
(defonce ticks i64)
(defn tick [] i64
(set ticks (+ ticks 1))
ticks)
(defn main [args [string]] i32
(if (< (length args) 2)
(do (println "usage: agent-queue <socket>") 2)
(do
(if (< (agent/start (at args 1)) 0)
(do (println "cannot listen") 1)
(do
(println "ready")
(stdin-byte)
;; How many the ring actually held. Every module queued is installed
;; here, so this number is the count of slots that survived — which
;; is the whole claim: a ring that overwrote the slot it was reading
;; would answer with something else.
(print (agent/poll)) (println "")
;; Round two: one evaluated expression, whose rendering is longer
;; than the 4K the dev runtime will hold. The program has to still be
;; here afterwards for the value to be read back off the socket, so
;; it waits a third time and leaves on end of file.
(stdin-byte)
(print (agent/poll)) (println "")
(stdin-byte)
0)))))