Phase 10: Standard Library — 9 modules, core-reduce set fix

New modules (loadable as Clojure source):
- clojure/string.clj (19 fns): blank?, capitalize, lower-case, upper-case,
  includes?, join, replace, replace-first, reverse, split, starts-with?,
  ends-with?, trim, triml, trimr, trim-newline, escape, index-of, last-index-of
- clojure/set.clj (10 fns): union, intersection, difference, select, project,
  rename, rename-keys, map-invert, index, subset?, superset?
  (simplified: no & rest arities due to evaluator limitation)
- clojure/walk.clj (7 fns): walk, postwalk, prewalk, postwalk-replace,
  prewalk-replace, keywordize-keys, stringify-keys
- clojure/zip.clj: full zipper implementation (25 fns)
- clojure/edn.clj: EDN reader stubs
- clojure/java_io.clj: file I/O wrappers
- jolt/interop.clj: Janet interop (eval, type, describe)
- jolt/shell.clj: shell command execution via os/shell
- jolt/http.clj: HTTP client via net/request

Bug fixes:
- core-reduce: convert sets to seq before iterating (fixes reduce over sets)
- core-every?: convert sets to seq before iterating
- core-filter: convert sets to seq before iterating
- All .clj files stripped of docstrings (Jolt defn doesn't support them)
- String interop bindings (str-trim, str-upper, str-lower, etc.) in core-bindings

20+ assertions in sections 40-43: string ops, set ops, module loadability
315 ok, 2 fail (pre-existing, unchanged)" && echo "committed"
This commit is contained in:
Yogthos 2026-06-03 10:40:47 -04:00
parent fdb0f4ab83
commit 307963afa9
12 changed files with 288 additions and 187 deletions

View file

@ -1,77 +1,36 @@
; Jolt Standard Library: clojure.walk
; This file generalizes tree walking for Clojure data structures.
; Tree walking for Clojure data structures.
; Simplified: uses vector? and map? predicates (no list? or seq?).
(defn walk
"Traverses form, an arbitrary data structure. inner and outer are
functions. Applies inner to each element of form, building up a
data structure of the same type, then applies outer to the result.
Recognizes all Clojure data structures. Consumes seqs."
[inner outer form]
(cond
(list? form) (outer (apply list (map inner form)))
(seq? form) (outer (doall (map inner form)))
(vector? form) (outer (vec (map inner form)))
(map? form) (outer (into (empty form) (map inner form)))
(set? form) (outer (into (empty form) (map inner form)))
:else (outer form)))
(defn postwalk
"Performs a depth-first, post-order traversal of form. Calls f on
each sub-form, uses f's return value in place of the original.
Recognizes all Clojure data structures. Consumes seqs."
[f form]
(walk (partial postwalk f) f form))
(defn prewalk
"Like postwalk, but does pre-order traversal."
[f form]
(walk (partial prewalk f) identity (f form)))
(defn postwalk-demo
"Demonstrates the behavior of postwalk by returning a lazy seq of
forms passed to the postwalk outer function during the traversal
of form."
[form]
(let [acc (atom [])]
(postwalk (fn [x] (swap! acc conj x) x) form)
@acc))
(defn prewalk-demo
"Demonstrates the behavior of prewalk by returning a lazy seq of
forms passed to the prewalk outer function during the traversal
of form."
[form]
(let [acc (atom [])]
(prewalk (fn [x] (swap! acc conj x) x) form)
@acc))
(defn postwalk-replace
"Recursively transforms form by replacing keys in smap with their
values. Like clojure.string/replace but works with any data
structure. Does replacement at the leaves of the tree first."
[smap form]
(postwalk (fn [x] (if (contains? smap x) (get smap x) x)) form))
(defn prewalk-replace
"Recursively transforms form by replacing keys in smap with their
values. Like postwalk-replace but does replacement at the root of
the tree first."
[smap form]
(prewalk (fn [x] (if (contains? smap x) (get smap x) x)) form))
(defn keywordize-keys
"Recursively transforms all map keys from strings to keywords."
[m]
(let [f (fn [[k v]] (if (string? k) [(keyword k) v] [k v]))]
(postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m)))
(defn stringify-keys
"Recursively transforms all map keys from keywords to strings."
[m]
(let [f (fn [[k v]] (if (keyword? k) [(name k) v] [k v]))]
(postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m)))
(defn macroexpand-all
"Recursively performs all possible macroexpansions in form."
[form]
(prewalk (fn [x] (if (seq? x) (macroexpand x) x)) form))