Index

SVCC Session Setup

I’m going to be writing a small program during the session. Here’s how to set up your system if you’d like to work along with me.

What is ClojureScript?

Clojure is a dialect of Lisp that runs on the Java Virtual Machine. ClojureScript is the name for:

Get Java 8

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.

Get Leiningen and Create a Project

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 session, 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 session, change to that directory, and create a figwheel project named example. Here is the sequence of commands:

mkdir session
cd session
lein new figwheel example

Mac OSX or Linux

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.

Get a Text Editor

Any text editor will do for this session. 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

Bookmark This Page

At some point, we will be creating a a couple of projects. 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.

Calculating Pythagorean Distance

<!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>Pythagorean Distance</title>
  </head>
  <body>
      <div id="app">
        <h1>Pythagorean Distance</h1>
        <p>
          a = <input type="text" id="a"/>
          b = <input type="text" id="b"/>
          c = <span id="c"/>
        </p>
        <p>
          <input type="button" id="calculate" value="Calculate"/>
        </p>
    </div>
    <script src="js/compiled/example.js" type="text/javascript"></script>
  </body>
</html>

Basic Statistics

<!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> <!-- if time permits -->
      </p>

    </div>
    <script src="js/compiled/example.js" type="text/javascript"></script>
  </body>
</html>