core: start Phase 4 — move vary-meta and namespace-munge to the overlay
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.
This commit is contained in:
parent
8bc5bd6f61
commit
e6ff4b8a77
4 changed files with 20 additions and 6 deletions
|
|
@ -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)))))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))"])
|
||||
|
|
|
|||
|
|
@ -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\")"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue