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-packages
then find Org,i
to mark it for installation,x
to install. - Then load the
literate-ants.org
file w/ Emacs withCTRL-x-f
. - Produce or "tangle" the Clojure source file from it, the keyboard shortcut is
CTRL-c-v-t
. - Start a shell within the same directory where the
.org
and new.clj
files are, runlein deps
thenlein repl
. - Start the ants simulator from the REPL with the expression below (it's also in the last section of
literate-ants.org
):
(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))
Assuming you're looking at the literate-ants.org
file from within Emacs24 with Org mode active:
SHIFT-TAB
will cycle the display: top-level headings only, all headings, or fully-expanded.CTRL-c-v-t
will tangle code; Org will process each code block below, and generate the source fileliterate-ants.clj
- Within a code block,
CTRL-c-'
will open a buffer to edit the code. For full power, be sure the Emacs packages ofclojure-mode
,paredit
, andnrepl
are installed - fairly straightforward using ELPA: from Emacs24 just doM-x package-list-packages
, move the cursor to the package of interest, hiti
to mark it for installation, hitx
to proceed with installation. - Export this file to HTML with
CTRL-c-e h
or, to export AND see it immediately in a browser window,CTRL-c-e b
. - Org docs: main documentation especially sections on structure, links, markup, and literate programming features.
The original ants.clj
source is copyright (c) Rich Hickey; all rights reserved. This literate programming version is copyright (c) Kai Wu.
Both ants.clj
and literate-ants.org
are distributed under the Common Public License 1.0.