Clojure Ants - a Literate Programming Version
This is a literate programming style version of Rich Hickey's Clojure ants simulator, using Emacs and the peerless Org mode. It's meant mainly as a demonstration of the literate programming capabilities of Org mode.
NOTE: if you're reading this on Github and click on the link above for the
literate-ants.org file, what you'll see is NOT the intended formatting, Github does not render
*.org files correctly. Instead, please view the file from within Emacs Org mode.
- You'll need a recent version of Emacs (e.g. 24.3.x) as well as Org mode (7.9.x, or 8.x). For Ubuntu users, you can install a current version of Emacs using Damien Cassou's PPA. Once Emacs loads, do
M-x list-packagesthen find Org,
ito mark it for installation,
- Then load the
literate-ants.orgfile w/ Emacs with
- Produce or "tangle" the Clojure source file from it, the keyboard shortcut is
- Start a shell within the same directory where the
.cljfiles are, run
- Start the ants simulator from the REPL with the expression below (it's also in the last section of
(do (load-file "./literate-ants.clj") ; Might be *.clojure on some systems! (def ants (setup)) (send-off animator animation) (dorun (map #(send-off % behave) ants)) (send-off evaporator evaporation))
Essentials to try/read
Assuming you're looking at the
literate-ants.org file from within Emacs24 with Org mode active:
SHIFT-TABwill cycle the display: top-level headings only, all headings, or fully-expanded.
CTRL-c-v-twill tangle code; Org will process each code block below, and generate the source file
- Within a code block,
CTRL-c-'will open a buffer to edit the code. For full power, be sure the Emacs packages of
nreplare installed - fairly straightforward using ELPA: from Emacs24 just do
M-x package-list-packages, move the cursor to the package of interest, hit
ito mark it for installation, hit
xto proceed with installation.
- Export this file to HTML with
CTRL-c-e hor, to export AND see it immediately in a browser window,
- Org docs: main documentation especially sections on structure, links, markup, and literate programming features.
ants.clj source is copyright (c) Rich Hickey; all rights reserved. This literate programming version is copyright (c) Kai Wu.
literate-ants.org are distributed under the Common Public License 1.0.