Clojure is a modern programming language. Depending on your skill level, you can create any type of software with Clojure. This includes games, web apps, mobile apps, and desktop applications.
The first step in programming Clojure is to install it and other things needed for creating Clojure programs.
Most of the Clojure tutorials and Clojure examples on this site require at the minimum Clojure to be installed. Usually, you want Leiningen installed too.
Easy peasy.
Seriously, do it once and ignore it for the rest of your learning experience. Here are the steps for getting Lein and Clojure up and running.
Sometimes you need to configure
lein to use a custom JDK. On Linux, set the environment variable
JAVA_CMD to point to the
java executable you want
lein to use.
For example, you might add the following lines to your
.bash_profile
1
2
3
4
5
#used by LEIN
JAVA_CMD=$HOME/installs/jdk-11.0.10+8/bin/java
export JAVA_CMD
Once you update your bash profile, you can start using your configuration by using the following command.
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
print and
println . For example,
1
(println"Hello world!")
That’s probably the first Clojure program you ever wrote. Maybe you wrote this variation.
1
(print"Hello world!")
Because
println or
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
prn and
pr commands. These two commands are tailored for printing objects. At first glance, they appear to work the same as
print and
println . However, they actually show more information in some instances.
If using
print or
println , the
\n in the following code quietly gets replaced by the action of a new line being printed.
1
(pr"Hello\nworld!")
When
pr or
prn are used, the two characters
\ and
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
pr and
prn , is that
prn prints a new line after the objects it is printing out.