Source: src/hql/lib/stdlib/js/internal/seq-protocol.js, src/hql/lib/stdlib/js/core.js, src/hql/lib/stdlib/stdlib.hql
HQL implements Clojure-inspired lazy sequences built on a Symbol-based protocol system. Lazy sequences defer computation until values are needed, enable infinite data structures, and provide memory-efficient processing.
hql.seq) with first(), rest(), seq() methods(cons head tail)range, repeat, cycle, iterate;; Infinite lazy sequence
(take 5 (range)) ;; => (0 1 2 3 4)
;; Lazy transformations (nothing computed until consumed)
(take 3 (filter isOdd (range))) ;; => (1 3 5)
;; Infinite fibonacci
(fn fib-seq [a b]
(lazy-seq (cons a (fib-seq b (+ a b)))))
(take 10 (fib-seq 0 1)) ;; => (0 1 1 2 3 5 8 13 21 34)
;; Cons cells
(cons 1 (cons 2 (cons 3 null))) ;; => (1 2 3)
;; Nil-punning
(seq []) ;; => null
(seq [1]) ;; => ArraySeq(1)
;; Delay/Force
(let d (delay (expensive-computation)))
(force d) ;; evaluates and caches
(realized d) ;; => true
| Type | Description | Protocols |
|---|---|---|
| EMPTY | Singleton empty sequence | SEQ, COUNTED, INDEXED |
| Cons | Immutable (first, rest) pair | SEQ |
| LazySeq | Memoized lazy thunk | SEQ |
| ArraySeq | View over array | SEQ, COUNTED, INDEXED |
| ChunkedCons | Chunked lazy sequence | SEQ |