From 77c52553cb7da84d43173588353ad39c4b72431f Mon Sep 17 00:00:00 2001 From: Yogthos Date: Thu, 4 Jun 2026 14:55:11 -0400 Subject: [PATCH] fix: REPL lazy-seq printer walks full chain (capped); def/defn return var (prints #'ns/name); fix var-name printer bug --- .beads/interactions.jsonl | 1 + .beads/issues.jsonl | 2 +- src/jolt/evaluator.janet | 3 ++- src/jolt/main.janet | 34 ++++++++++++++++++++-------------- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.beads/interactions.jsonl b/.beads/interactions.jsonl index 77f6811..cf2efc3 100644 --- a/.beads/interactions.jsonl +++ b/.beads/interactions.jsonl @@ -9,3 +9,4 @@ {"id":"int-677fb0a5","kind":"field_change","created_at":"2026-06-04T18:40:42.396722Z","actor":"Yogthos","issue_id":"jolt-40n","extra":{"field":"status","new_value":"closed","old_value":"open"}} {"id":"int-10c63325","kind":"field_change","created_at":"2026-06-04T18:40:43.31635Z","actor":"Yogthos","issue_id":"jolt-4z9","extra":{"field":"status","new_value":"closed","old_value":"open"}} {"id":"int-ba29d2c7","kind":"field_change","created_at":"2026-06-04T18:45:52.297233Z","actor":"Yogthos","issue_id":"jolt-gxr","extra":{"field":"status","new_value":"closed","old_value":"open"}} +{"id":"int-b7e06923","kind":"field_change","created_at":"2026-06-04T18:55:10.600885Z","actor":"Yogthos","issue_id":"jolt-7n5","extra":{"field":"status","new_value":"closed","old_value":"open"}} diff --git a/.beads/issues.jsonl b/.beads/issues.jsonl index 0ce18a4..96923de 100644 --- a/.beads/issues.jsonl +++ b/.beads/issues.jsonl @@ -11,5 +11,5 @@ {"_type":"issue","id":"jolt-9sb","title":"HIGH: destructuring gaps (nested seq, :strs, nested map, fn-param)","status":"closed","priority":2,"issue_type":"bug","owner":"yogthos@gmail.com","created_at":"2026-06-04T18:09:55Z","created_by":"Yogthos","updated_at":"2026-06-04T18:31:24Z","closed_at":"2026-06-04T18:31:24Z","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"jolt-7dy","title":"MED: compiler path lacks IFn dispatch (collections-as-fn) — only interpreter fixed","status":"open","priority":3,"issue_type":"bug","owner":"yogthos@gmail.com","created_at":"2026-06-04T18:10:00Z","created_by":"Yogthos","updated_at":"2026-06-04T18:10:00Z","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"jolt-90c","title":"MED: filter/take-while not lazy — infinite-seq (take N (filter p (range))) loops","status":"open","priority":3,"issue_type":"bug","owner":"yogthos@gmail.com","created_at":"2026-06-04T18:10:00Z","created_by":"Yogthos","updated_at":"2026-06-04T18:10:00Z","dependency_count":0,"dependent_count":0,"comment_count":0} -{"_type":"issue","id":"jolt-7n5","title":"MED: REPL display — def/defn should print #'ns/name; lazy-seq printer realizes only head ((0 \u003cfunction\u003e))","status":"open","priority":3,"issue_type":"bug","owner":"yogthos@gmail.com","created_at":"2026-06-04T18:09:59Z","created_by":"Yogthos","updated_at":"2026-06-04T18:09:59Z","dependency_count":0,"dependent_count":0,"comment_count":0} +{"_type":"issue","id":"jolt-7n5","title":"MED: REPL display — def/defn should print #'ns/name; lazy-seq printer realizes only head ((0 \u003cfunction\u003e))","status":"closed","priority":3,"issue_type":"bug","owner":"yogthos@gmail.com","created_at":"2026-06-04T18:09:59Z","created_by":"Yogthos","updated_at":"2026-06-04T18:55:11Z","closed_at":"2026-06-04T18:55:11Z","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"jolt-h0n","title":"MED: missing core fns — letfn fnil trampoline doseq cycle partition-all reductions dedupe keep-indexed map-indexed transduce reduce-kv assoc-in peek subvec read-string format","status":"open","priority":3,"issue_type":"feature","owner":"yogthos@gmail.com","created_at":"2026-06-04T18:09:58Z","created_by":"Yogthos","updated_at":"2026-06-04T18:09:58Z","dependency_count":0,"dependent_count":0,"comment_count":0} diff --git a/src/jolt/evaluator.janet b/src/jolt/evaluator.janet index dd7aab2..95aa8a9 100644 --- a/src/jolt/evaluator.janet +++ b/src/jolt/evaluator.janet @@ -485,7 +485,8 @@ (bind-root v val) (when dynamic? (put v :dynamic true)) - (var-get v)) + # def returns the var (Clojure semantics); REPL prints #'ns/name + v) "defmacro" (let [name-sym (in form 1) rest-form (tuple/slice form 2) # optional docstring diff --git a/src/jolt/main.janet b/src/jolt/main.janet index 694167b..f730c78 100644 --- a/src/jolt/main.janet +++ b/src/jolt/main.janet @@ -3,6 +3,7 @@ (use ./api) (use ./types) +(use ./phm) (def ctx (init)) (ctx-set-current-ns ctx "user") @@ -32,21 +33,26 @@ (++ i))) (push-str buf "]")) - # LazySeq — realize and print as a list + # LazySeq — realize the cell chain and print as a list. Capped to avoid + # hanging on infinite sequences; prints "..." when truncated. (and (table? v) (= :jolt/lazy-seq (v :jolt/type))) (do - (def val (if (get v :realized) (v :val) (let [vf ((v :fn))] (put v :realized true) (put v :val vf) vf))) - (if (nil? val) - (push-str buf "()") - (do - (push-str buf "(") - (var i 0) - (let [n (length val)] - (while (< i n) - (write-value (in val i) buf) - (when (< (+ i 1) n) (push-str buf " ")) - (++ i))) - (push-str buf ")")))) + (push-str buf "(") + (var cur v) + (var i 0) + (var go true) + (while (and go (< i 1000)) + (let [cell (realize-ls cur)] + (if (or (nil? cell) (= :jolt/pending cell) (= 0 (length cell))) + (set go false) + (do + (when (> i 0) (push-str buf " ")) + (write-value (in cell 0) buf) + (++ i) + (let [rt (in cell 1)] + (if (nil? rt) (set go false) (set cur (make-lazy-seq rt)))))))) + (when (and go (>= i 1000)) (push-str buf " ...")) + (push-str buf ")")) (array? v) (do @@ -119,7 +125,7 @@ (push-str buf (string ns "/" name)) (push-str buf name))) (and (table? v) (= :jolt/var (v :jolt/type))) - (push-str buf (string "#'" (ctx-current-ns ctx) "/" ((var-name v) :name))) + (push-str buf (string "#'" (ctx-current-ns ctx) "/" (var-name v))) (or (tuple? v) (array? v) (struct? v) (table? v)) (write-collection v buf) true (push-str buf (string v)))))