Information about our Clojure project is contained within our project.clj
file. We can read in this file and check the project information in that way.
The slurp
function reads in the contents of a file or content from a web page / URL.
Read the Clojure
project.clj
file using theslurp
function
(slurp "project.clj")
The output of slurping the project file should similar to the following
Tidy up the result of the
slurp
value using the functionread-string
(read-string (slurp "project.clj"))
Really we just want to get the project version, not all the information. As a list is returned from slurp
and read-string
then we can simply wrap a function around the first two functions to get the value we want
The nth
funtion takes the data structure as the first argument and the element number (starting from zero) as the second argument.
Use the
nth
function withread-string
andslurp
to select the element we actually want.
(nth (read-string (slurp "project.clj")) 2)