Function | Example expression | Return value | |
---|---|---|---|
|
|
||
#() reader macro |
|
|
|
|
|
||
|
|
||
|
|
||
|
|
Several functions are provided to print objects to the output stream that is the current value of *out*
. The -str versions bind *out*
to a StringWriter, print to that, and return the resulting string. pr prints the object(s), separated by spaces if there is more than one. prn does the same and follows it with a newline. print and println call pr and prn respectively, with *print-readably*
(which defaults to true) bound to nil, which causes strings to print without surrounding quotes or any escape character encoding, and characters to print without the leading '\', or any escape character encoding. By default, pr and prn print in a way that objects can be read by the reader, while print and println produce output for human consumption. When *print-readably*
is non-nil, the printing of metadata is toggled by *print-meta*
, which defaults to nil.
Print to *out*
: pr prn print println newline
Print to string: pr-str prn-str print-str println-str with-out-str
Regex patterns can be compiled at read-time via the #"pattern"
reader macro, or at run time with re-pattern. Both forms produce java.util.regex.Pattern objects.
user=> (re-seq #"[0-9]+" "abs123def345ghi567")
("123" "345" "567")
user=> (re-find #"([-+]?[0-9]+)/([0-9]+)" "22/7")
["22/7" "22" "7"]
user=> (let [[a b c] (re-matches #"([-+]?[0-9]+)/([0-9]+)" "22/7")]
[a b c])
["22/7" "22" "7"]
user=> (re-seq #"(?i)[fq].." "foo bar BAZ QUX quux")
("foo" "QUX" "quu")