I’m going to be writing a small program during the webcast. Here’s how to set up your system if you’d like to work along with me.
Clojure is a dialect of Lisp that runs on the Java Virtual Machine. ClojureScript is the name for:
The ClojureScript compiler is written in Java, so make sure you have Java 8 installed. If you aren’t sure if you have Java, type this from a command prompt:
java -version
You should see something like this as a result:
java version "1.8.0_40" Java(TM) SE Runtime Environment (build 1.8.0_40-b26) Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
If you get an error message or you don’t have Java 8, go to Oracle’s Java download page, get the version of the Java Runtime Environment (JRE) or Java Development Kit (JDK) for your system, and install it according to their instructions.
Leiningen is a script that automates the building of Clojure and ClojureScript projects. Go to leiningen.org and install the Leiningen script as per the instructions on that website.
In the webcast, I’ll be using a Leiningen plugin named figwheel that builds your ClojureScript and automatically loads it into the browser when you save a changed version of your source files. Create a directory for the webcast, change to that directory, and create a figwheel project named example. Here is the sequence of commands:
mkdir webcast cd webcast lein new figwheel example
Install the rlwrap
utility. This utility will let you use the arrow keys to move up and down through command history and left and right to edit within a line when using ClojureScript in its interactive mode. On Mac OSX, use Homebrew or MacPorts to install; on Linux, use your distribution’s package manager.
Any text editor will do for this webcast. Here are several choices, in case you don’t have a favorite already.
jEdit | Cross-platform (written in Java) |
Geany | Cross-platform |
Notepad++ | Windows |
Light Table | Cross-platform; very good for editing Clojure |
IntelliJ IDEA (with Cursive plugin) | Cross-platform |
vim | cross-platform |
GNU emacs | cross-platform |
At some point, we will be creating a project to do basic statistics. To save you some time and lots of typing, you will replace the index.html file in the project’s resources/public directory with this HTML.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="css/style.css" rel="stylesheet" type="text/css"> <title>Statistics</title> </head> <body> <div id="app"> <h1>Statistics</h1> <p>Enter a list of numbers separated by blanks or commas:<br/> <input type="text" size="40" id="numbers"/> <input type="button" id="calculate" value="Calculate"/> </p> <p> Mean: <span id="mean"></span><br /> Standard deviation: <span id="stdv"></span> </p> </div> <script src="js/compiled/stats.js" type="text/javascript"></script> </body> </html>