search


Hello Clojure
Wed Jun 06 00:00:00 UTC 2018

The first thing to do when learning a new programming language is to write an obligatory 'hello world' program. The reason 'hello world' is the first program to write is because it is simple and sucessfully running hello world is a good test that your development environment is setup and configured correctly. We've been using Power Turtle and Maria Cloud because there is no required setup and software installation but to do any serious development you will need a local development environment.

We will be using mainly emacs. Emacs has a relatively high learning curve but it has the benefit of allowing you to code remotely on a server. The majority of Clojure/LISP programmers use emacs for development so there is good tooling and support. However, if you prefer a traditional graphical IDE download and install Intellij Community Edition IntelliJ is an open source Java IDE that supports Clojure/ClojureScript development with the Cursive Plugin Cursive is commercial but as a student you can get a free license

Setup for Windows

If you're using windows 10, install ubuntu for Windows using this tutorial . Once you've installed Ubuntu for Windows, follow the setup instructions for Ubuntu below

Setup For Ubuntu

Open a shell and run the following commands one line at a time. The % represents the command prompt and not what you should type. Type the commands after the % prompt.


% sudo add-apt-repository ppa:kelleyk/emacs 
% sudo apt-get update 
% sudo apt install wget git openjdk-8-jdk emacs26-nox tmux 
% wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
% chmod a+x lein
% sudo mv lein /usr/local/bin
% mkdir -p ~/.emacs.d/lisp
% wget -c https://www.emacswiki.org/emacs/download/doremi.el -O ~/.emacs.d/lisp/doremi.el
% wget -c https://www.emacswiki.org/emacs/download/doremi-cmd.el -O ~/.emacs.d/lisp/doremi-cmd.el
% wget -c https://raw.githubusercontent.com/clojure-emacs/clj-refactor.el/master/clj-refactor.el -O ~/.emacs.d/lisp/clj-refactor.el
% wget -c https://bit.ly/2NlZY2G -O ~/.emacs.d/init.el
% wget -c https://bit.ly/2uNg1ic -O ~/.tmux.conf

After this start the Clojure REPL using lein. Then type (prn "hello world") like below


% lein repl

nREPL server started on port 33333 on host 127.0.0.1 - nrepl://127.0.0.1:33333
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_151-b12
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Source: (source function-name-here)
Javadoc: (javadoc java-object-or-class-here)
Exit: Control+D or (exit) or (quit)
Results: Stored in vars *1, *2, *3, an exception in *e

user=> (prn "hello world")
"hello world"
nil
user=>

To exit the repl and return to the command prompt, type Ctrl-D

Setup for Mac

Download JDK 8 for mac. Make sure to download jdk 8 and not 9 or 10. Lein has not been upgraded to be compatible with jdk 9 or 10. Once you've downloaded the JDK, make sure it is executable in your shell. by typing

% java -version

% wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
% chmod a+x lein
% sudo mv lein /usr/local/bin
% mkdir -p ~/.emacs.d/lisp
% wget -c https://www.emacswiki.org/emacs/download/doremi.el -O ~/.emacs.d/lisp/doremi.el
% wget -c https://www.emacswiki.org/emacs/download/doremi-cmd.el -O ~/.emacs.d/lisp/doremi-cmd.el
% wget -c https://raw.githubusercontent.com/clojure-emacs/clj-refactor.el/master/clj-refactor.el -O ~/.emacs.d/lisp/clj-refactor.el
% wget -c https://bit.ly/2NlZY2G -O ~/.emacs.d/init.el
% wget -c https://bit.ly/2uNg1ic -O ~/.tmux.conf

Follow instruction for starting a Clojure REPL in the Ubuntu section.