1.2.0 permalink Arrow_down_16x16
  • (dochars bindings & body)
bindings => [name string]

Repeatedly executes body, with name bound to each character in
string. Does NOT handle Unicode supplementary characters (above
U+FFFF).

1 Example top

  • (require '[clojure.contrib.str-utils2 :as s])
    
    user=> (s/dochars [c "ABC"] (println c))
    A
    B
    C
    nil
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/str_utils2.clj:40 top

(defmacro dochars 
  "bindings => [name string]

  Repeatedly executes body, with name bound to each character in
  string.  Does NOT handle Unicode supplementary characters (above
  U+FFFF)."
  [bindings & body]
  (assert (vector bindings))
  (assert (= 2 (count bindings)))
  ;; This seems to be the fastest way to iterate over characters.
  `(let [^String s# ~(second bindings)]
     (dotimes [i# (.length s#)]
       (let [~(first bindings) (.charAt s# i#)]
         ~@body))))
Vars in clojure.contrib.str-utils2/dochars: = assert count defmacro first second vector apply concat dotimes hash-map let list seq with-meta
Used in 0 other vars

Comments top

No comments for dochars. Log in to add a comment.