#268 Variadic / broken: inline call silently drops args past the 2nd; fn cell is binary-only; (/ x) reciprocal returns garbage

closed
Opened by atgreen

Found comparing against SBCL at the REPL (2026-07-10, build/funcl @ 5cc5f39).

Symptom 1: inline / silently drops arguments past the second

CL-USER> (/ 345 436 33 5734 72 247)
345/436          ; SBCL: 115/489064694976
CL-USER> (/ 12 2 3)
6                ; should be 2

No error — extra divisors are silently ignored. This is a wrong-answer bug, worse than a missing feature.

Symptom 2: the / function cell is binary-only

CL-USER> (funcall #'/ 12 2 3)
; Error: invalid number of arguments: / expected 2, got 3 | in: FUNCALL
CL-USER> (apply #'/ (list 12 2 3))
; Error: invalid number of arguments: / expected 2, got 3 | in: APPLY

Symptom 3: one-argument reciprocal form is broken

CL-USER> (/ 12)
; Error: The value (-216172782110176742 . ?) is not of type NUMBER. | in: /

(/ x) should return 1/x (CLHS). The garbage cons in the error message suggests the arg list itself is being handed to the numeric path.

Not affected

+, -, * all handle >2 args correctly through the inline path:

CL-USER> (- 10 1 2 3)   => 4
CL-USER> (+ 1 2 3 4)    => 10
CL-USER> (* 2 3 4)      => 24

So / is missing the left-fold reduction the other three arith ops already have (likely in both the inline emit path and the prelude fn-cell definition), plus the 1-arg (/ x)(/ 1 x) special case.

Comments (2)

atgreen3992785764

STILL BROKEN, fresh data (2026-07-11): (/ 12 2 2) => 6 — the inline 2-arg emitter takes the call site and SILENTLY DROPS args past the 2nd (stdlib variadic / defun is correct but only backs funcall/apply). (/ 4) => a malformed value that crashes prin1 ('The value (-216172782110176742 . ?) is not of type NUMBER') — the reciprocal path produces a broken ratio-shaped object. Two fixes needed: (a) emit-ir div dispatch should fold >2 args or fall back to the defun; (b) the (/ 1 n) inline ratio construction is corrupt — compare with %make-ratio (cave#282 fixed GC tracing for ratios; this looks like the construction, not tracing).

atgreen3992797307

FIXED: the / inline emitter is now arity-gated to exactly 2 args (cave#213 append pattern); (/ a) and (/ a b c ...) route to the prelude's variadic defun. This fixed BOTH sub-issues at once — the arg-dropping AND the garbage reciprocal (1-arg was mis-entering the 2-arg emitter). Probes: (/ 12 2 2)=3, (/ 24 2 3 2)=2, (/ 4)=1/4, (float (/ 4))=0.25, funcall #'/ variadic correct. The 'fn cell is binary-only' sub-item was already resolved by the variadic defun backing #'/.