NOTE: All the code in this tutorial can be quickly tested at the REPL using the command
leinrepl to start a REPL to test with.
One of the first things you learn when learning clojure is
println . For example,
That’s probably the first Clojure program you ever wrote. Maybe you wrote this variation.
print are the first ways learned of displaying output in Clojure, most Clojure developers continue using them when debugging code. Nothing wrong with that. But sometimes it is better to use a more specialized tool.
In steps the
pr commands. These two commands are tailored for printing objects. At first glance, they appear to work the same as
println . However, they actually show more information in some instances.
println , the
\n in the following code quietly gets replaced by the action of a new line being printed.
prn are used, the two characters
n are displayed instead of an actual new line. This is very handy when hidden characters are fowling up your layout, or needed to be visible when debugging code.
Final note: The only difference between
prn , is that
prn prints a new line after the objects it is printing out.