read-string

clojure.core

  • (read-string s)
Reads one object from the string s

4 Examples top

  • user=> (read-string "1.1")          
    1.1
    
    user=> (read-string "1.1.1 (+ 1 1)")
    java.lang.RuntimeException: java.lang.NumberFormatException: Invalid number: 1.1.1 (NO_SOURCE_FILE:0)
    
    user=> (read-string "(+ 1 1)")
    (+ 1 1)
    
  • user=> (eval (read-string "(+ 1 1)"))
    2
    
    user=> (read-string (prn-str (+ 1 1)))
    2
    
  • user=> (+ 11 (read-string "23"))
    34
    
  • user=> (read-string "; foo\n5")
    5
    
    user=> (read-string "#^String x")
    x
    
    user=> (read-string "(1)")
    (1)
    
    user=> (read-string "(+ 1 2) (- 3 2)")
    (+ 1 2)
    
    user=> (read-string "@a")
    (clojure.core/deref a)
    
    user=> (read-string "(+ 1 2))))))")
    (+ 1 2)
    
    user=> (read-string "::whatever-namespace-you-are-in")
    :user/whatever-namespace-you-are-in
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:3355 top

(defn read-string
  "Reads one object from the string s"
  {:added "1.0"
   :static true}
  [s] (clojure.lang.RT/readString s))
Vars in clojure.core/read-string:
Used in 0 other vars

Comments top

No comments for read-string. Log in to add a comment.