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:
parent
32a1fff1b8
commit
09c4cb2242
1 changed files with 12 additions and 8 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
(use ./types)
|
(use ./types)
|
||||||
|
|
||||||
(def ctx (init))
|
(def ctx (init))
|
||||||
|
(ctx-set-current-ns ctx "user")
|
||||||
|
|
||||||
(defn read-line [prompt]
|
(defn read-line [prompt]
|
||||||
(prin prompt)
|
(prin prompt)
|
||||||
|
|
@ -87,16 +88,19 @@
|
||||||
|
|
||||||
(set print-value (fn [v]
|
(set print-value (fn [v]
|
||||||
(cond
|
(cond
|
||||||
(nil? v) (print "nil")
|
(nil? v) (prin "nil")
|
||||||
(= true v) (print "true")
|
(= true v) (prin "true")
|
||||||
(= false v) (print "false")
|
(= false v) (prin "false")
|
||||||
(number? v) (print v)
|
(number? v) (prin v)
|
||||||
(string? v) (print v)
|
(string? v) (prin v)
|
||||||
(keyword? v) (prin ":") (print (string 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)))
|
(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))
|
(or (tuple? v) (array? v) (struct? v) (table? v))
|
||||||
(print-collection v)
|
(do (print-collection v) (print))
|
||||||
(print v))))
|
(print v))))
|
||||||
|
|
||||||
(defn main [&]
|
(defn main [&]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue