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:
parent
fdb0f4ab83
commit
307963afa9
12 changed files with 288 additions and 187 deletions
|
|
@ -7,8 +7,7 @@
|
|||
(= 0 (count (str-trim s)))))
|
||||
|
||||
(defn capitalize
|
||||
"Converts first character of the string to upper-case, all other
|
||||
characters to lower-case."
|
||||
|
||||
[s]
|
||||
(if (< 1 (count s))
|
||||
(str (str-upper (subs s 0 1))
|
||||
|
|
@ -16,79 +15,78 @@
|
|||
(str-upper s)))
|
||||
|
||||
(defn lower-case
|
||||
"Converts string to all lower-case."
|
||||
|
||||
[s]
|
||||
(str-lower s))
|
||||
|
||||
(defn upper-case
|
||||
"Converts string to all upper-case."
|
||||
|
||||
[s]
|
||||
(str-upper s))
|
||||
|
||||
(defn includes?
|
||||
"True if s includes substr."
|
||||
|
||||
[s substr]
|
||||
(not (nil? (str-find substr s))))
|
||||
|
||||
(defn join
|
||||
"Returns a string of all elements in coll, separated by
|
||||
an optional separator."
|
||||
|
||||
([coll] (str-join coll))
|
||||
([separator coll] (str-join coll separator)))
|
||||
|
||||
(defn replace
|
||||
"Replaces all instance of match with replacement in s."
|
||||
|
||||
[s match replacement]
|
||||
(str-replace-all match s replacement))
|
||||
|
||||
(defn replace-first
|
||||
"Replaces the first instance of pattern in string with replacement."
|
||||
|
||||
[s match replacement]
|
||||
(str-replace match s replacement))
|
||||
|
||||
(defn str-reverse
|
||||
"Returns s with its characters reversed."
|
||||
|
||||
[s]
|
||||
(str-reverse-b s))
|
||||
|
||||
(defn split
|
||||
"Splits string on a regular expression. Optional limit."
|
||||
|
||||
([s re]
|
||||
(map str-trim (str-split re s)))
|
||||
([s re limit]
|
||||
(take limit (split s re))))
|
||||
|
||||
(defn starts-with?
|
||||
"True if s starts with substr."
|
||||
|
||||
[s substr]
|
||||
(let [slen (count s) slen2 (count substr)]
|
||||
(and (>= slen slen2)
|
||||
(= (subs s 0 slen2) substr))))
|
||||
|
||||
(defn ends-with?
|
||||
"True if s ends with substr."
|
||||
|
||||
[s substr]
|
||||
(let [slen (count s) slen2 (count substr)]
|
||||
(and (>= slen slen2)
|
||||
(= (subs s (- slen slen2)) substr))))
|
||||
|
||||
(defn trim
|
||||
"Removes whitespace from both ends of string."
|
||||
|
||||
[s]
|
||||
(str-trim s))
|
||||
|
||||
(defn triml
|
||||
"Removes whitespace from the left side of string."
|
||||
|
||||
[s]
|
||||
(str-triml s))
|
||||
|
||||
(defn trimr
|
||||
"Removes whitespace from the right side of string."
|
||||
|
||||
[s]
|
||||
(str-trimr s))
|
||||
|
||||
(defn trim-newline
|
||||
"Removes all trailing newline \\n or return \\r characters from string."
|
||||
|
||||
[s]
|
||||
(var result s)
|
||||
(while (or (= (subs result (dec (count result))) "\n")
|
||||
|
|
@ -97,7 +95,7 @@
|
|||
result)
|
||||
|
||||
(defn escape
|
||||
"Return a new string, using cmap to escape each character ch from s."
|
||||
|
||||
[s cmap]
|
||||
(apply str
|
||||
(map (fn [ch]
|
||||
|
|
@ -105,8 +103,7 @@
|
|||
s)))
|
||||
|
||||
(defn index-of
|
||||
"Return index of value (string or char) in s, optionally
|
||||
from start. Returns nil if not found."
|
||||
|
||||
([s value]
|
||||
(let [idx (str-find value s)]
|
||||
(when idx (inc idx))))
|
||||
|
|
@ -115,7 +112,7 @@
|
|||
(when idx (+ from (inc idx))))))
|
||||
|
||||
(defn last-index-of
|
||||
"Return last index of value (string or char) in s."
|
||||
|
||||
([s value]
|
||||
(let [r (str-reverse-b s) sval (str-reverse-b value)
|
||||
idx (str-find sval r)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue