Due:

Note: This assignment will not be graded.

Learning Clojure

We will be using Clojure for a series of programming assignments.

The Functional programming with Clojure MOOC at the University of Helsinki is a truly excellent way to learn Clojure. In this assignment you will work on the first four chapters. There are two Milestones:

You can find the chapters on the Material and course content page.

Programming environment

The Basic tools chapter covers the software you will need.

I recommend using Eclipse with the Counterclockwise plugin. You can install this through the Eclipse marketplace (search for “counterclockwise”).

As an alternative to Eclipse and Counterclockwise, you can try using Light Table. You can also use Emacs as described in the textbook.

The computers in KEC 119 have Eclipse with Counterclockwise and Local Terminal.

Using Git

The programming activities for each chapter are in a Git repository on GitHub. The recommended way of starting each chapter is to fork the repository, and then clone your fork.

For example, after forking the training-day repository, I would clone my fork using the command

cd
cd git
git clone git@github.com:daveho/training-day

This would place the repository in the git subdirectory of my home directory (which is the recommended place to put local Git repositories.)

Importing the repository into your Eclipse workspace

If you are planning to use Eclipse and Counterclockwise, you will need to import the repository as an Eclipse project. To do so:

  1. Go the to Git perspective in Eclipse.
  2. In the Git Repositories view, click the “Add an existing local Git repository” button, and choose the local Git repository (e.g., training-day).
  3. Switch back to the Java perspective.
  4. Choose File→New→Project…→General→Project.
  5. Uncheck the “Use default location” checkbox. Use “Browse” to choose the directory containing your local Git repository (e.g., training-day). Enter the project name (e.g., training-day.)
  6. Click “Finish”. You should now see the project in your Eclipse workspace. The Clojure file you will need to edit will be in the src directory.
  7. Right-click on the project and choose Configure→Convert to Leiningen Project. (The “Progress Information” dialog may hang: just cancel it if this happens.)

Once you have set up the Eclipse project, you should commit your changes and push them to your fork. In general, it is a good idea to commit and push your changes to your GitHub repository as you work: your GitHub repository will serve as a record of your progress.

Testing your work

To run the unit tests for a programming activity:

  1. In a terminal, run the command cd $HOME && cd path-to-repo, where path-to-repo is the path to the local git repository containing your work. (E.g., git/training-day.)
  2. Next, run the command lein midje. The output will indicate how many tests passed and which tests (if any) failed.

If you get an error from Leiningen about midje not being a valid task, try deleting the .lein directory (in your home directory) and running the command again.

To test your functions interactively (highly recommended!):

  1. Start a terminal and cd into the repository directory (as described above).
  2. Run the command lein repl to start a read-eval-print loop.
  3. Enter (use 'namespace), where namespace is the namespace defined for the chapter, e.g., i-am-a-horse-in-the-land-of-booleans
  4. Now you can call functions defined in your source code. If you modify your code, you can run (use 'namespace :reload) to reload your code in the REPL session.