flan/test/programs/println-variadic.flan
Joseph Ferano 2b91fd2146 print and println go variadic, with Clojure's spacing
Arguments print in order with a single space between each pair, println
ending the line; (println) is the newline alone and (print) is nothing.
The checker's arm renders each argument exactly as it did alone, so typed
and dyn values mix in one call, one-argument sites are byte-identical, and
an unprintable argument is still refused at its own span.
2026-09-20 22:09:06 +07:00

34 lines
1.3 KiB
Plaintext

;;;; print and println are variadic with Clojure's spacing: every argument
;;;; prints in order, a single space between each pair, println ending the
;;;; line. (println) alone is the newline; (print) alone is nothing.
;;;;
;;;; What the pins are for. The one-argument lines must be byte-identical to
;;;; what they printed before the forms went variadic — no trailing space is
;;;; the thing an eye cannot see in a diff, so every print line ends in a "|"
;;;; marker that would move if a space leaked. And the arguments are typed and
;;;; dyn in the same call: each gets the walk it would get alone, the typed
;;;; ones selected at check time and the dyn ones handed to the runtime, so
;;;; the interleaving on one line is what proves the two sinks share a buffer.
(defvar boxed dyn 21)
(defvar dlabel dyn "mid")
(defn main [] ()
;; println at every arity
(println) ; bare newline
(println "one") ; the old single-argument form, unchanged
(println "a" "b")
(println "x:" 5 true)
;; mixed machine types in one call
(println 1 2.5 "s" false)
;; dyn and typed in the same call, dyn in the middle
(println "pre" boxed "post")
(println dlabel 7)
;; print: zero args is nothing, and no separator ever trails
(print)
(print "|")
(print "p")
(print "|")
(print "q" "r" 3)
(println "|"))