Clojure resources

Because much of the work in our group uses the Clojure programming language, I thought it would be useful to post a general list of Clojure resources here, aimed primarily at beginners.

There are many more!

But the intention here is to present a reasonably concise curated list.

An even more curated set of “Clojure quickstart instructions,” recommending a single setup and a particular set of learning materials for newcomers, and including more explicit instructions, is available here.

Clojure resources

  • Editing and running code: For some workflows you will want to install the command-line Leiningen utility, which can be used to create, manage, and run complete projects (with “lein run”). Some of the text below assumes that you are using leiningen, although the CLI tools are becoming more popular and may be a better choice for many purposes. Several integrated development environments (IDEs) are available. Whichever you use, it is strongly recommended that you make use of the “auto-reindentation” feature, which in some cases requires that a plugin be installed or configured. Also recommended that you turn off “strict mode” or “paredit” or “parinfer” if you want to type/cut/paste like you can in other contexts (I do!). Recommended IDEs include:

    • IntelliJ with Cursive. You only need the free “community” version. Note that you can install java from within IntelliJ, in the process of creating your first Clojure project, which may save you from complications that can otherwise arise in installing Java. Turn off structural editing by selecting “Structural Off” in the lower right corner of the window, where it has probably defaulted to “Paredit.” You can also turn off the automatic insertion of closing brackets by selecting “Preferences” from the IntelliJ IDEA menu, then twisting down “Editor” in the panel on the left, then twisting down “General,” then selecting (but not twisting down) “Smart Keys,” and then unchecking the “Use paired brackets (), [], {}, <>” option in the main panel.
    • Visual Studio Code with Calva. Calva doesn’t currently have a command to create a new project, but if you’ve installed it you can use Leiningen at the command line to make one with something like lein new app myproject. Or you could create a deps.edn project from scratch as described here. To start a REPL, use the command palette to invoke “Calva: Start a project REPL and connect (a.k.a. Jack-In).” To evaluate a top-level expression in the editor pane: With the cursor in or just after the expression, hold down the option (or Alt) key and hit return (or enter). When trying to evaluate expressions in a file, be sure to evaluate the namespace (ns) declaration at the top of the file first. Results will appear inline in the editor (but they’re not really in the file!) and also in the REPL pane. Clear the inline results from the editor pane by hitting the esc key. There’s a bit more detail on using Calva here. If you have a Github account, there is now also a zero-installation way to run Calva in your browser: GitHub - PEZ/minimal-clojure: A minimal Clojure project for web based development
    • Gorilla REPL: A worksheet environment that can be useful for certain kinds of experiments of even as a full development environment. The Gorilla REPL site has videos that will give you a sense of how it works, and a section called “Secrets,” with content provided by me, that I think will also help to get you going.
  • The Clojurians Slack is probably the best place for realtime, interactive community support these days. There are many channels there, including #beginners, #cursive, and #calva. Some other Q&A forums are listed here.

  • Clojure.org, the main site for the Clojure language; note especially their Clojure resources page

  • Clojure cheatsheet

  • ClojureDocs, a community-powered documentation and examples repository

  • Clojure style guide

  • Clojure TV

  • Clojure in a nutshell by James Trunk, a nice video to watch when getting started, although you might want to go with a different setup than the command line or vi, which is what is mostly used here (and a little VSCode/Calva).

  • Lee’s tutorial materials:

    • Clojestions, suggested exercises for learning Clojure

    • Clojinc, a saved REPL session intended to support semi-independent learning of Clojure

  • Other tutorial materials:

  • A good free textbook: Clojure for the Brave and True by Daniel Higginbotham. No Starch Press, 2015. ISBN-10: 1593275919, ISBN-13: 978-1593275914. Available free online

  • Tips for using Clojure on Windows

  • Two blog posts on dealing with Clojure error messages (stack traces): 1 and 2

  • If you want to integrate Clojure and Python code, check out libpython-clj.

  • For data science applications, check out the data tables and related functions provided by tablecloth. Also, although it’s still being developed as of the time of this writing, check out the Clojure Data Cookbook. And more generally, check out Scicloj.

  • Lee’s Clojure GP code:

    • Propeller, “Yet another Push-based genetic programming system in Clojure,” under active development to become a leaner, cleaner and more flexible research platform than Clojush.

    • Propel, a relatively simple, easy-to-understand but nonetheless fully functional PushGP implementation (a fork of @thelmuth’s project) that provided the foundation for Propeller.

    • Clojush, a long-established research PushGP system that has been used for many projects and publications, with a zillion features but also a lot of cruft and unhelpful complexity

    • gp, simple Clojure code for traditional, “tree-based” genetic programming (not Push), which is also explained in this talk

  • Clojure MXNet, for the Apache MXNet deep learning framework

  • Simple Clojure neural network code by Hampshire student Julian Oks

  • When running Clojush programs from command line (and something similar will apply to other GP systems or other long-running Clojure processes), a command like “lein run clojush.problems.demos.simple-regression | tee out” will print the output on the console as well as save it in a file named “out”. The advantage with doing things this way is that you can search for important things in the file using ‘grep’. For example if you want to search for all the lines that starts with ‘Total’, you can use “grep Total out

  • To make Clojush (and other long-running, computationally intensive Clojure programs) run faster, you can use a command like:
    lein with-profiles production trampoline run clojush.problems.software.digits. The output will remain the same.

  • A few of Lee’s other Clojure projects of possible interest:

    • Rock Paper Stuff, a game designed for artificial intelligence experiments and education

    • Pucks, an environment for experiments and education in artificial intelligence and artificial life

  • Quil, a Clojure/ClojureScript library for creating interactive drawings and animations

2 Likes