From e6ff4b8a7745f21c74717c215f68843058d9ee1b Mon Sep 17 00:00:00 2001 From: Yogthos Date: Sun, 7 Jun 2026 20:00:19 -0400 Subject: [PATCH] =?UTF-8?q?core:=20start=20Phase=204=20=E2=80=94=20move=20?= =?UTF-8?q?vary-meta=20and=20namespace-munge=20to=20the=20overlay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First Phase 4 batch: the host-coupled fns whose logic is pure composition of existing core primitives, so no new jolt.host surface is needed. vary-meta is just (with-meta obj (apply f (meta obj) args)); namespace-munge is a char map over str. Both land in the 20-coll tier; the Janet core-* defns and bindings are gone. Added namespace-munge spec cases and a vary-meta extra-args case. The heavily host-coupled fns (atom/var/transient internals, arrays, proxy, futures) stay in Janet pending a thin host-primitive expansion. --- jolt-core/clojure/core/20-coll.clj | 12 ++++++++++++ src/jolt/core.janet | 8 ++------ test/spec/metadata-spec.janet | 1 + test/spec/strings-spec.janet | 5 +++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/jolt-core/clojure/core/20-coll.clj b/jolt-core/clojure/core/20-coll.clj index 03bd0eb..22651af 100644 --- a/jolt-core/clojure/core/20-coll.clj +++ b/jolt-core/clojure/core/20-coll.clj @@ -213,3 +213,15 @@ (recur (assoc m (first xs) (second xs)) (next (next xs))) m)) s)) + +;; Phase 4 (jolt-1j0): host-coupled fns that are pure logic over existing core +;; primitives, so they need no new jolt.host surface. + +;; vary-meta: f applied to obj's metadata (+ extra args), reattached. meta and +;; with-meta are the irreducible host primitives; vary-meta is just their compose. +(defn vary-meta [obj f & args] + (with-meta obj (apply f (meta obj) args))) + +;; namespace-munge: Clojure namespace name -> legal Java package name (- -> _). +(defn namespace-munge [s] + (apply str (map (fn [c] (if (= c \-) \_ c)) (seq (str s))))) diff --git a/src/jolt/core.janet b/src/jolt/core.janet index 596e1ff..b11fe0e 100644 --- a/src/jolt/core.janet +++ b/src/jolt/core.janet @@ -1805,8 +1805,6 @@ (defn core-clojure-version [] "1.11.0-jolt") (defn core-munge [s] (string/replace-all "-" "_" (string s))) -(defn core-namespace-munge [s] - (string/replace-all "-" "_" (string s))) (defn core-test [v] (let [t (and (core-meta v) (get (core-meta v) :test))] (if t (do (t) :ok) :no-test))) @@ -2375,8 +2373,8 @@ # keys must be numbers (NaN allowed) — like Clojure, which compares them with . # min-key / max-key now live in the Clojure collection tier (core/20-coll.clj). -(defn core-vary-meta [obj f & args] - (let [m (core-meta obj)] (core-with-meta obj (apply f m args)))) +# vary-meta / namespace-munge now live in the Clojure collection tier +# (core/20-coll.clj) — pure compositions of meta/with-meta and str/map. # Exceptions (ex-info / ex-data / ex-message) (defn core-ex-info [msg data & more] @@ -2876,7 +2874,6 @@ "associative?" core-associative? "ifn?" core-ifn? "indexed?" core-indexed? - "vary-meta" core-vary-meta "ex-info" core-ex-info "ex-data" core-ex-data "ex-message" core-ex-message @@ -3009,7 +3006,6 @@ "class" core-class "clojure-version" core-clojure-version "munge" core-munge - "namespace-munge" core-namespace-munge "test" core-test "enumeration-seq" core-enumeration-seq "iterator-seq" core-iterator-seq diff --git a/test/spec/metadata-spec.janet b/test/spec/metadata-spec.janet index e92b3c0..aa1b4b5 100644 --- a/test/spec/metadata-spec.janet +++ b/test/spec/metadata-spec.janet @@ -7,6 +7,7 @@ ["with-meta preserves value" "true" "(= [1 2 3] (with-meta [1 2 3] {:a 1}))"] ["with-meta on map" "{:doc \"x\"}" "(meta (with-meta {:k 1} {:doc \"x\"}))"] ["vary-meta" "{:a 2}" "(meta (vary-meta (with-meta [1] {:a 1}) update :a inc))"] + ["vary-meta extra args" "{:a 1 :b 2}" "(meta (vary-meta (with-meta [1] {:a 1}) assoc :b 2))"] ["meta reader ^" "{:tag :int}" "(meta ^{:tag :int} [1 2])"] ["with-meta on fn ok" "true" "(fn? (with-meta inc {:a 1}))"] ["with-meta nil clears" "nil" "(meta (with-meta [1 2 3] nil))"]) diff --git a/test/spec/strings-spec.janet b/test/spec/strings-spec.janet index e57b6e6..18f247d 100644 --- a/test/spec/strings-spec.janet +++ b/test/spec/strings-spec.janet @@ -48,3 +48,8 @@ ["subs end past len" :throws "(subs \"abcde\" 1 6)"] ["subs nil start" :throws "(subs \"abcde\" nil 2)"] ["subs on nil" :throws "(subs nil 1 2)"]) + +(defspec "string / namespace-munge" + ["hyphens to underscores" "\"a_b_c\"" "(namespace-munge \"a-b-c\")"] + ["from a symbol" "\"foo_bar\"" "(namespace-munge (quote foo-bar))"] + ["no hyphens unchanged" "\"ok\"" "(namespace-munge \"ok\")"])