Skip to content
 
 

Latest commit

 

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ants Simulation in Clojure

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 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.

TODO

  • Test parts of the simulation using clojure.spec
  • Use clojure.spec to generate ants, pheromones, etc
  • Improve dev workflow so one can make real-time changes through the REPL
  • Achieve greater simplicity

Prerequisites

  1. You will need Java
  2. And Clojure
  3. As well as lein
  4. (Optional) Install Docker too

Running the simulation

This project uses lein. Run it with:

$ lein run

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

Resources

Original Notice

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

Copyright (c) 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.

About

Refactored version of Rich Hickey's Ant Simulation in Clojure

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages