From 09c4cb22425017160087e4e1b19e09f52c6a3ee5 Mon Sep 17 00:00:00 2001 From: Yogthos Date: Tue, 2 Jun 2026 23:48:17 -0400 Subject: [PATCH] Fix REPL collection rendering + namespace initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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. --- src/jolt/main.janet | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/jolt/main.janet b/src/jolt/main.janet index 299358b..5de3b4d 100644 --- a/src/jolt/main.janet +++ b/src/jolt/main.janet @@ -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 [&]