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

35 lines
1.3 KiB
Plaintext

;;;; The agent, end to end: a running program takes a redefinition over a
;;;; socket and installs it between "frames".
;;;;
;;;; [tick] is the function that gets redefined. It is called once before any
;;;; reload and once after each of two of them, and nothing else in this file
;;;; changes, so the three numbers are the whole result. Two reloads and not
;;;; one because that is the daemon's actual loop: a second module built from
;;;; the same session, reading state the first one introduced.
;;;;
;;;; It waits rather than polling on a timer because a test that races the
;;;; frame rate is a test that fails on a loaded machine. A game loop calls
;;;; poll at the top of the frame and ignores the answer; the split is in
;;;; vendor/agent/agent.flan.
(import agent "vendor:agent")
(defonce ticks i64)
(defn tick [] i64
(set ticks (+ ticks 1))
ticks)
(defn main [args [string]] i32
(if (< (length args) 2)
(do (println "usage: agent <socket>") 2)
(do
(if (< (agent/start (at args 1)) 0)
(do (println "cannot listen") 1)
(do
(print (tick)) (println "")
(while (= (agent/wait 100) 0) 0)
(print (tick)) (println "")
(while (= (agent/wait 100) 0) 0)
(print (tick)) (println "")
0)))))