ClojureDocs

导航

命名空间

字符串中的 with

clojure.core

自 1.0 起可用 (源代码)
  • (with-in-str s & body)
Evaluates body in a context in which *in* is bound to a fresh
StringReader initialized with the string s.
1 Example
;; Given you have a function that will read from *in*
(defn prompt [question]
  (println question)
  (read-line))

user=> (prompt "How old are you?")
How old are you?
34                   ; <== This is what you enter
"34"                 ; <== This is returned by the function

;; You can now simulate entering your age at the prompt by using with-in-str

user=> (with-in-str "34" (prompt "How old are you?"))
How old are you?
"34"                 ; <== The function now returns immediately 
See Also

Evaluates exprs in a context in which *out* is bound to a fresh StringWriter. Returns the string ...

Added by ryo
0 Notes
No notes for with-in-str