Experiment: Native Multiple Values(v1 · en)

Multiple values are a return protocol, not a collection: zero values, one nil, and several values are distinct, and a single-value context takes the primary. Every step here runs in a native session without std.cl; observations come from real runner deliveries (see Values and Expressions).

Seed code

(defun divmod (a b)
  ;; ADR-053: 除法是精确除法(=17/5= 是有理数)——本实验要的是整数商,
  ;; 显式 floor 保住 divmod 的整数语义;mod 本来就是 floor 语义。
  (values (floor (/ a b)) (mod a b)))
(defun hop [n]
  (if (= n 0) (values :end nil) (hop (- n 1))))

Steps

Step 1: Multiple values are actually bound and compute the expected result

(def result
  (multiple-value-bind (q r) (divmod 17 5)
    (+ (* q 100) r)))
(println result)

Expected observation: stdout is 302. 17 ÷ 5 = 3 remainder 2 — multiple-value-bind binds q to 3 and r to 2 (the two returned values are really bound, not a list unpacked), and the arithmetic composes 3×100+2=302. Simulated primaries or failed binding would produce a different number.

Step 2: Zero values and one nil are distinct deliveries (a protocol, not a collection)

(println (count (multiple-value-list (values))))
(println (count (multiple-value-list (values nil))))
(println (count (multiple-value-list (values 1 2 3))))

Expected observation: stdout is 0, 1, 3 in turn. (values) delivers zero values (empty list), (values nil) delivers one nil (single-element list) — the return protocol distinguishes them; ordinary collections do not.

Step 3: Multiple values survive a tail-call chain

(multiple-value-bind (a b) (hop 1000)
  (println a)
  (println b))

Expected observation: stdout is :end then nil. hop recurs 1000 levels deep (tail calls, no frame growth) and the delivered values survive the whole chain — the return protocol does not degrade to the primary under TCO.

Step 4: multiple-value-call concatenates into a dynamic-arity call

(println (multiple-value-call + (divmod 17 5) (values 100)))

Expected observation: stdout is 105. Each form's delivery concatenates in order as arguments (3, 2, 100); the argument count is determined at runtime and + receives three.

步骤总览

步骤预期观察
Step 1: Multiple values are actually bound and compute the expected resultstdout is =302=. =17 ÷ 5 = 3 remainder 2= — =multiple-value-bind= binds =q= to =3= and =r= to =2= (the two returned values are really bound, not a list unpacked), and the arithmetic composes =3×100+2=302=. Simulated primaries or failed binding would produce a different number.
Step 2: Zero values and one nil are distinct deliveries (a protocol, not a collection)stdout is =0=, =1=, =3= in turn. =(values)= delivers zero values (empty list), =(values nil)= delivers one nil (single-element list) — the return protocol distinguishes them; ordinary collections do not.
Step 3: Multiple values survive a tail-call chainstdout is =:end= then =nil=. =hop= recurs 1000 levels deep (tail calls, no frame growth) and the delivered values survive the whole chain — the return protocol does not degrade to the primary under TCO.
Step 4: multiple-value-call concatenates into a dynamic-arity callstdout is =105=. Each form's delivery concatenates in order as arguments (=3=, =2=, =100=); the argument count is determined at runtime and =+= receives three.

无 JS 执行会话

下面的原生表单创建一个执行会话(服务端 P6-b runner 子进程求值,本页进程不执行用户代码);会话页内逐步运行、查看观察、重置或关闭。

JSON API 同一能力走 POST /api/experiments;两条路径共用同一 runner 合同。