TL;DR
clojure.core/read
is used to read "code" by Clojure itself
clojure.edn/read
is used to read "data" (EDN)
read-line
is used to read text lines as string; it's your problem to
decipher them
What can read
do for you
read
does not only read symbols, but anything, that Clojure uses to
represent code. If you give it a symbol to parse, it will give you
symbol back:
(type (read))
test
clojure.lang.Symbol
But also other things
(type (read))
5
java.lang.Long
(type (read))
{:a 42}
clojure.lang.PersistentArrayMap
(type (read))
"hello"
java.lang.String
So you can get back a string with read
too, if you feed it a string.
real-world use of read
Usually read
is used by Clojure itself and that's it. Reading
EDN is usually done using clojure.edn/read
, which does not allow code
execution and therefor is no security risk if handling EDN from
untrusted sources.
docs
For good measure, here are the docs:
(doc read)
-------------------------
clojure.core/read
([] [stream] [stream eof-error? eof-value] [stream eof-error? eof-value recursive?] [opts stream])
Reads the next object from stream, which must be an instance of
java.io.PushbackReader or some derivee. stream defaults to the
current value of *in*.
Opts is a persistent map with valid keys:
:read-cond - :allow to process reader conditionals, or
:preserve to keep all branches
:features - persistent set of feature keywords for reader conditionals
:eof - on eof, return value unless :eofthrow, then throw.
if not specified, will throw
Note that read can execute code (controlled by *read-eval*),
and as such should be used only with trusted sources.
For data structure interop use clojure.edn/read
(doc read-line)
-------------------------
clojure.core/read-line
([])
Reads the next line from stream that is the current value of *in* .
(read)
consumes the stream and a following call to(read-line)
no longer sees the content consumed byread
? Maybe it would be best to show your actual problem? – cfrick Feb 19 at 10:15(read) (read)
twice to parse a line with two words... but I faced that(read)
is not what I thought it is, hence my request. – Joël Feb 20 at 11:53