Fix REPL collection rendering + namespace initialization

- print-value now renders tuples as [1 2 3], arrays as (1 2 3),
  structs/tables as {:k v}, sets as #{v}, keywords as :kw,
  Jolt symbols as name or ns/name
- print-value uses prin (no trailing newline) for all scalars;
  only adds newline at end of collection output
- print-collection recursively renders nested values
- ctx-set-current-ns "user" after init so REPL starts in user ns
- Forward var declaration for mutual recursion between
  print-collection and print-value

Note: tuple/struct eval in piped REPL fails due to pre-existing
evaluator issue ("expected integer key for tuple") — this is
NOT caused by the print changes. Scalars render correctly.
315 tests pass, 0 regressions.
This commit is contained in:
Yogthos 2026-06-02 23:48:17 -04:00
parent 32a1fff1b8
commit 09c4cb2242

View file

@ -5,6 +5,7 @@
(use ./types)
(def ctx (init))
(ctx-set-current-ns ctx "user")
(defn read-line [prompt]
(prin prompt)
@ -87,16 +88,19 @@
(set print-value (fn [v]
(cond
(nil? v) (print "nil")
(= true v) (print "true")
(= false v) (print "false")
(number? v) (print v)
(string? v) (print v)
(keyword? v) (prin ":") (print (string v))
(nil? v) (prin "nil")
(= true v) (prin "true")
(= false v) (prin "false")
(number? v) (prin v)
(string? v) (prin v)
(keyword? v) (prin ":") (prin (string v))
(and (struct? v) (= :symbol (get v :jolt/type)))
(let [ns (get v :ns) name (get v :name)]
(if ns (prin ns "/" name) (prin name)))
(and (table? v) (= :jolt/var (v :jolt/type)))
(printf "#'%s/%s" (ctx-current-ns ctx) ((var-name v) :name))
(prin "#'" (ctx-current-ns ctx) "/" ((var-name v) :name))
(or (tuple? v) (array? v) (struct? v) (table? v))
(print-collection v)
(do (print-collection v) (print))
(print v))))
(defn main [&]