clojure.string toString coercion; some-fn/ifn? reference semantics; misc host gaps
The clojure.string case fns and searches now take any Object s through its toString like the reference's ^CharSequence signatures ((upper-case :kw) is ":KW", (capitalize 1) is "1"); nil throws, and a nil substr in starts-with?/ends-with? throws. some-fn re-ported with the reference arities: (some-fn) is an arity error and a no-match result is the last predicate's own falsy value (false, not nil). ifn? covers multimethods, promises (which are now invocable — calling one delivers, via a cold-path invoke-arm registry that costs the hot dispatch nothing), and deftypes implementing IFn's invoke. One structural find on the way: defmulti/defmethod deferred inside a fn body (the deftest pattern) interned/resolved in whatever namespace was current when they RAN, not the one they were written in — the macros now bake their expansion ns and the setups honor it. Also: Boolean/Integer/Double wrapper ctors, primitive TYPE statics (Integer/TYPE etc.), .reduce on collections (IReduce), and Long/TYPE. cts baseline 5857 -> 5904 pass, 58 -> 28 errors, 57 baselined namespaces — the string cluster, some-fn, ifn-qmark, boolean-qmark, and reduce namespaces are all fully clean. 7 JVM-certified corpus rows; spec entry.
This commit is contained in:
parent
a9542077fc
commit
e17bcfd0af
15 changed files with 1100 additions and 941 deletions
|
|
@ -6,28 +6,32 @@
|
|||
(if (nil? s) true
|
||||
(= 0 (count (str-trim s)))))
|
||||
|
||||
;; The case fns and the searches take any Object s through its toString, like
|
||||
;; the reference ((upper-case :kw) is ":KW", (capitalize 1) is "1"); nil throws
|
||||
;; like calling a method on null.
|
||||
(defn- to-str [s]
|
||||
(if (nil? s)
|
||||
(throw (new NullPointerException "s"))
|
||||
(.toString s)))
|
||||
(defn capitalize
|
||||
|
||||
[s]
|
||||
(if (< 1 (count s))
|
||||
(str (str-upper (subs s 0 1))
|
||||
(str-lower (subs s 1)))
|
||||
(str-upper s)))
|
||||
(let [s (to-str s)]
|
||||
(if (< 1 (count s))
|
||||
(str (str-upper (subs s 0 1))
|
||||
(str-lower (subs s 1)))
|
||||
(str-upper s))))
|
||||
|
||||
(defn lower-case
|
||||
|
||||
[s]
|
||||
(str-lower s))
|
||||
(str-lower (to-str s)))
|
||||
|
||||
(defn upper-case
|
||||
|
||||
[s]
|
||||
(str-upper s))
|
||||
(str-upper (to-str s)))
|
||||
|
||||
(defn includes?
|
||||
|
||||
[s substr]
|
||||
(not (nil? (str-find substr s))))
|
||||
(not (nil? (str-find substr (to-str s)))))
|
||||
|
||||
(defn join
|
||||
|
||||
|
|
@ -36,11 +40,11 @@
|
|||
|
||||
(defn replace
|
||||
[s match replacement]
|
||||
(str-replace-all match replacement s))
|
||||
(str-replace-all match replacement (to-str s)))
|
||||
|
||||
(defn replace-first
|
||||
[s match replacement]
|
||||
(str-replace match replacement s))
|
||||
(str-replace match replacement (to-str s)))
|
||||
|
||||
(defn reverse
|
||||
[s]
|
||||
|
|
@ -68,16 +72,18 @@
|
|||
(vec (str-split #"\r?\n" s)))
|
||||
|
||||
(defn starts-with?
|
||||
|
||||
[s substr]
|
||||
(let [slen (count s) slen2 (count substr)]
|
||||
(when (nil? substr) (throw (new NullPointerException "substr")))
|
||||
(let [s (to-str s)
|
||||
slen (count s) slen2 (count substr)]
|
||||
(and (>= slen slen2)
|
||||
(= (subs s 0 slen2) substr))))
|
||||
|
||||
(defn ends-with?
|
||||
|
||||
[s substr]
|
||||
(let [slen (count s) slen2 (count substr)]
|
||||
(when (nil? substr) (throw (new NullPointerException "substr")))
|
||||
(let [s (to-str s)
|
||||
slen (count s) slen2 (count substr)]
|
||||
(and (>= slen slen2)
|
||||
(= (subs s (- slen slen2)) substr))))
|
||||
|
||||
|
|
@ -97,8 +103,8 @@
|
|||
(str-trimr s))
|
||||
|
||||
(defn escape
|
||||
|
||||
[s cmap]
|
||||
(when (nil? s) (throw (new NullPointerException "s")))
|
||||
(apply str
|
||||
(map (fn [ch]
|
||||
(if-let [rep (cmap ch)] rep (str ch)))
|
||||
|
|
@ -107,9 +113,9 @@
|
|||
(defn index-of
|
||||
"0-based index of the first occurrence of value in s, or nil."
|
||||
([s value]
|
||||
(str-find value s))
|
||||
(str-find value (to-str s)))
|
||||
([s value from]
|
||||
(let [idx (str-find value (subs s from))]
|
||||
(let [idx (str-find value (subs (to-str s) from))]
|
||||
(when idx (+ from idx)))))
|
||||
|
||||
(defn last-index-of
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue