clojure-ants-simulation

Refactored version of Rich Hickey's Ant Simulation in Clojure

Ants Simulation in Clojure

This project uses lein. Run it with:

# Or just use lein run directly
$ make start

demo-sample

You can also run it using Docker, but unfortunately in macOS there are extra steps to connect Docker with X11. I’ve tested it with macOS Sierra, Docker for Mac (1.13.1) and XQuartz 2.7.11 (xorg-server 1.18.4).

# Right now, you have to run build every time you make a change to the source
$ make docker/build

# Remember to have X11 running
$ make docker/start

# Remove container and image
$ make docker/clean

Motivation

After watching Rich’s great talk about concurrency in Clojure, I wanted to experiment with his original Ants Simulation and learn more about concurrency, agents, refs, state management, etc.

I ended up refactoring the original solution, because:

  • State is used in far too many places. deref is the norm. It’s hard to spot pure functions.
  • Naming is generally bad, with lots of abbreviations and bindings with one char.
  • It has one big namespace, which makes things more confusing when you’re trying to follow along and make changes.
  • It doesn’t read well, i.e. you need to read and re-read every function source to grasp what’s going on.
  • It lacks the functional punch we all love! Example: most functions are using lets, sometimes as much as 6 bindings. It feels imperative code in many ways and lacks composability.

Having said all of that, I had tons of fun and learned a lot playing around with this simulation.

Resources

Original Notice

Ants is based on the Clojure Ants Simulation by Rich Hickey.

Copyright © Rich Hickey. All rights reserved. The use and distribution terms for this software are covered by the Common Public License 1.0 ([http://opensource.org/licenses/cpl1.0.php][cpl]) which can be found in the file cpl.txt at the root of this distribution. By using this software in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any other, from this software.

Related Repositories

clojure-ants-simulation

clojure-ants-simulation

Clojure GUI Demo of Ant Colony - Simulation (by Rich Hickey) ...

clojure-ants-simulation

clojure-ants-simulation

Clojure GUI Demo of Ant Colony - Simulation (by Rich Hickey) ...

clojure-ants-simulation

clojure-ants-simulation

Refactored version of Rich Hickey's Ant Simulation in Clojure ...