Phase 7: LazySeq + PersistentHashSet completion

- phm.janet: LazySeq (realize-once with caching, ls-first/ls-rest/ls-seq/ls-count)
  PersistentHashSet (backed by PHM, phs-conj/phs-disj/phs-contains?/phs-count/...)
  make-lazy-seq creates lazy thunk wrapper with :jolt/lazy-seq type tag
  make-phs creates hash set with :jolt/set type tag
- evaluator.janet: :jolt/set handler in eval-form, disj/set? special forms,
  special-symbol? entries, phm import for compile-time visibility
- core.janet: lazy-seq/iterate macros, set?/disj core fns, make-phs wired
  into hash-set, core-bindings entries for set?/disj/lazy-seq/make-lazy-seq/iterate
  Set support in core-conj/core-contains?/core-count/core-empty?/core-seq/core-get
  LazySeq support in core-first/core-rest/core-count/core-seq
- 9 tests (32-33): lazy-seq basic ops, realize-once caching
  PersistentHashSet construction, conj, disj, count, set? predicate
- 315 ok, 2 fail (pre-existing, unchanged)
This commit is contained in:
Yogthos 2026-06-02 23:24:55 -04:00
parent f410f5c48b
commit fe22fea3e4
7 changed files with 286 additions and 133 deletions

25
test/phase7-test.janet Normal file
View file

@ -0,0 +1,25 @@
# Phase 7: LazySeq + PersistentHashSet completion
(use ../src/jolt/api)
(defn ct-eval [ctx s] (eval-string ctx s))
(print "32: lazy-seq...")
(let [ctx (init)]
(let [ls (ct-eval ctx "(lazy-seq (cons 1 (lazy-seq (cons 2 nil))))")]
(assert (not (nil? ls)) "lazy-seq returns non-nil")
(assert (= 1 (ct-eval ctx "(first (lazy-seq (cons 1 nil)))")) "first of lazy"))
(assert (= [1 2 3] (ct-eval ctx "(seq (lazy-seq [1 2 3]))")) "seq forces lazy")
(eval-string ctx "(def counter (atom 0))")
(def val (ct-eval ctx "(let [ls (lazy-seq (do (swap! counter inc) [1 2 3]))] (seq ls) (seq ls) @counter)"))
(assert (= 1 val) "realized once"))
(print " passed")
(print "33: PersistentHashSet...")
(let [ctx (init)]
(assert (= true (ct-eval ctx "(set? #{1 2 3})")) "set? true")
(assert (= false (ct-eval ctx "(set? [1 2 3])")) "set? false")
(assert (= 4 (ct-eval ctx "(count (conj #{1 2 3} 4))")) "conj add")
(assert (= 2 (ct-eval ctx "(count (disj #{1 2 3} 3))")) "disj")
(assert (= 3 (ct-eval ctx "(count #{1 2 3})")) "count"))
(print " passed")
(print "\nAll Phase 7 tests passed!")