Category Archives: Clojure

Growing a Language with Clojure and Instaparse

Creating your own programming language with Clojure and Instaparse is like building rainbows with s-expressions.  The Instaparse library is an elegant way of building executable parsers trees with pattern matching and standard EBNF notation for context-free grammars. Since this is my first foray into parser trees and grammars, I thought I would share my learnings in this post.

Starting with a Single Word

Let’s start with the simplest example:  a number.  When we start up our REPL in our brand new language, we want to be able to enter an integer, and have evaluate as an integer.

MyCoolLang> 1
1

Using the instaparse library, we define a number to be a regex matching an integer.

(ns coollang.parser
  (:require [instaparse.core :as insta]))
 
(def parser
  (insta/parser
   "number = #'[0-9]+'"))
 
(parser "1") ;=>; [:number "1"]

We now have a parser tree node that is of a type number. Pretty nice so far, but more rainbows are coming. You can make elegant transformations on the parser tree, and does them in a bottom up fashion, so you can use it for evaluation as well. In our simple number example, we are applying the read-string function on the :number node to turn it into a int.

(def transform-options
  {:number read-string})
 
(defn parse [input]
  (->> (parser input) (insta/transform transform-options)))
 
(parse "1") ;=> 1

Adding on spaces and vectors

Let’s build on a bit more. When someone enters in a sequence of numbers separated by spaces, it will be defined as a vector.

MyCoolLang> 1 2 3 4
[1 2 3 4]

We need to add the notion of spaces, spaces with numbers, and vectors into our grammar, as well as the rules
for evaluating these new nodes. Notice that we use the <> notation to hide the definition in the parser tree. The + means one or more times. The * means 0 or more times, and the | means or.

(def parser
  (insta/parser
   "expr = number | vector
    vector = snumber+ number
    <snumber> = (number space)*
    <space> = <#'[ ]+'>
    number = #'[0-9]+'"))
 
(parser "1 2 3 4") ;=> [:expr [:vector [:number "1"] [:number "2"] [:number "3"] [:number "4"]]]
 
(def transform-options
  {:number read-string
   :vector (comp vec list)
   :expr identity})
 
(defn parse [input]
  (->> (parser input) (insta/transform transform-options)))
 
(parse "1 2 3 4") ;=> [1 2 3 4]

Adding in operations

Pretty cool. We have numbers and vectors. Let’s see if we can do something fun like do some simple math on these vectors or numbers. We want it so when we type in + and some numbers, it adds them up.

MyCoolLang> + 1 2 3 4
10

Of course we need to further expand our grammar and rules.

(def parser
  (insta/parser
   "expr = number | vector | operation
    operation = operator space+ vector
    operator = '+' | '-' | '*' | '/'
    vector = snumber+ number
    <snumber> = (number space)*
    <space> = <#'[ ]+'>
    number = #'[0-9]+'"))
 
(parser "+ 1 2 3 4") ;=> [:expr
 ;                        [:operation
 ;                         [:operator "+"]
 ;                           [:vector [:number "1"] [:number "2"] [:number "3"] [:number "4"]]]
 
(defn choose-operator [op]
  (case op
    "+" +
    "-" -
    "*" *
    "/" /))
 
(def transform-options
  {:number read-string
   :vector (comp vec list)
   :operator choose-operator
   :operation apply
   :expr identity})
 
(defn parse [input]
  (->> (parser input) (insta/transform transform-options)))
 
(parse "+ 1 2 3 4") ;=> 10

Add a REPL

All we need now is a cool REPL to start working in:
We just need a main function to call our REPL, (Read – Evaluate – Print – Loop), and we are all set.

(ns coollang.repl
  (:require [coollang.parser :as parser]))
 
(defn repl []
  (do
    (print "MyCoolLang> ")
    (flush))
  (let [input (read-line)]
    (println (parser/parse input))
    (recur)))
 
(defn -main [&amp; args]
  (println "Hello MyCoolLang!")
  (println "===============")
  (flush)
  (repl))

Closing and Inspiration

I have enjoyed playing around and learning about creating programming languages with Clojure and instaparse.
It truly is a beautiful library. If you need any more inspiration to start creating your own programming language, may I recommend:

Now go forth and create!

drone

The Joy of Flying AR Drones with Clojure

Clojure is fun.  Flying AR Parrot Drones are fun.  Put them together and there is pure joy.

Ever since I found out that you could program and control your drone over UDP, I couldn’t wait to try it out in Clojure.  I had dreams of controlling it with my Emacs REPL.  That dream came true and it has been a true joy to fly in a function language. This blog post shows some of the features that the clj-drone project has so far.  There is still a bit of work to go to make it complete.  But, I wanted to share and hopefully encourage others to start playing with it too.

The Simple Take-off and Landing

(ns clj-drone.example.simple
  (:require [clj-drone.core :refer :all]))
 
(drone-initialize)
;Use ip and port for non-standard drone ip/port
;(initialize ip port)
(drone :take-off)
(Thread/sleep 10000)
(drone :land)

Here is a video of executing the entire program in nrepl/ emacs

Controlling the Drone with Emacs/ Clojure REPL

Running the program all at once to control the drone is fun. But, I prefer to have more control over it in flight. I find being able to execute commands with keystrokes in emacs, the best way to do it. Here is a short video demonstrating control via the REPL. (Note: I am just doing simple take off / up and landings because of the constraints of flying indoors in my kitchen. There are many more moves you can do if you have more space.)

(ns clj-drone.example.moves
  (:require [clj-drone.core :refer :all]))
 
(drone-initialize)
;Use ip and port for non-standard drone ip/port
;(initialize ip port)
(drone-do-for 4 :take-off)
(drone-do-for 2 :up 0.3)
(drone-do-for 3.75 :fly 0.2 0 0 0.5) ; sprial
(drone :hover)
(drone :land)

Looking at the Navigation Data

You can also hook into the navigation feed. There are many drone states and properties to look at. There is a list of all the ones currently available on the github project site. There are also many more, including targeting information, that have yet to be added. There is a logging function that will pair down the navigation properties that you are interested in. The navigation data map as an atom, so it can be de-referenced anywhere in your program. Here is a short video of what the navigation logging data looks like when it is turned on.

(ns clj-drone.example.nav-test
  (:require [clj-drone.core :refer :all]
            [clj-drone.navdata :refer :all]))
 
;; logging is configured to go to the logs/drone.log file
 
(set-log-data [:seq-num :flying :battery-percent :control-state :roll :pitch :yaw
                :velocity-x :velocity-y :velocity-z])
(drone-initialize)
(drone-init-navdata)
(drone :take-off)
(drone :land)
(end-navstream)

Auto-piloting with goals and beliefs

Inspired by reading John McCarthy’s paper on Ascribing Mental Qualities to Machines, the drone can also auto-pilot itself based on goals and beliefs about its streaming navigation data. You define belief-actions and then goals. Finally, you set a vector of the current goals for the drone to process. You can see an example here of the AR drone having three goals: Take off, Get to a cruising altitude, and then land. It does it solely by inspecting and acting on the streaming navigation data.
Code for the program is here: https://github.com/gigasquid/clj-drone/blob/master/examples/nav_goals.clj

Go Fly!

I have had a lot of fun so far working on this project. I hope that you get a chance to play with it too. The project is still very young, so stay tuned for updates and, of course, pull requests are always welcome :)

Hobby Languages for Clojurists

I spend most of my work day in Ruby and CoffeeScript. However, my true love belongs to Clojure, which I consider my “hobby” language right now. I started to wonder, what are the “hobby” languages for people who spend most of their work day with Clojure. My informal twitter poll revealed selection as diverse and interesting as the Clojurists themselves.

Developers Who Enjoy Clojure Also Enjoy:
(In no particular order)

and of course MORE Clojure

7 McCarthy Papers in 7ish Weeks #5 & #6 – SDFW Tic-Tac-Toe

SDFW Tic Tac Toe

This holiday edition blog post covers two McCarthy papers instead of just one.  We will be talking about Free Will – Even for Robots and the companion paper Simple Deterministic Free Will.

In which we deftly sidestep the philosophers

We know that computers and programs are completely deterministic.  A philosophical question is whether we, as humans are ruled by determinism, (although complex it may be), or not.  If we take the decision that humans are deterministic, then we can argue that either there is no free will – or that free will is “compatible” with determinism.  Philosophers, of course, could discuss such questions interminably, trying to get a theory to fit for all people and all occasions.  Thankfully, McCarthy takes a very admirable and practical view on free will.  Let’s try out something simple for a computer program and see how it works.  He explores a philosophy ”Compatibilist’s” view, which regards a person to have free will if his actions are decided by an internal process, even if this process itself is deterministic.  But by exploring this view with computer programs, he makes clear:

… I don’t need to take a position on determinism itself.

 

Simple Deterministic Free Will

So what would Free Will look like for a machine. How do we go about defining it? McCarthy proposes the idea of Simple Deterministic Free Will. The main idea is that the mechanism of free will is broken up into two parts. The first part looks at the possible actions and the consequences of those actions, and the second part decides which of those actions are preferable and does them. He gives the example of a chess program:

People and chess programs carry thinking about choice beyond the first level. Thus “If I make this move, my opponent (or nature regarded as an opponent) will have the following choices, each of which will give me further choices.” Examining such trees of possibilities is an aspect of free will in the world, but the simplest form of free will in a deterministic world does not involve branching more than once.

So perhaps we could find an example that is simpler than chess to work with …

…it would be interesting to design the simplest possible system exhibiting deterministic free will. A program for tic-tac-toe is simpler than a chess program, but the usual program does consider choices.

Simple Deterministic Free Will Tic Tac Toe

So to explore McCarthy’s idea of Simple Deterministic Free Will, I decided to try to construct a game of Tic Tac Toe with SDFW principles. Coincidentally, my six year old daughter, just learned how to play Tic Tac Toe as well. I wanted to construct a program that would “reason” about the game as would a child. Even though the game of Tic Tac Toe is simple enough to have all the possibility trees of moves completely solved, this is not how a my daughter approaches the game. Each time it is her move, she only looks one move ahead to see if she can win three in a row, or if she needs to block her opponent from winning the next move.

My Tic Tac Toe Program has Beliefs

It has three beliefs to be precise. It believes that no one is going to win, or it is going to win, or its opponent is going to win.

(def beliefs
  { :win "I am going to win."
    :lose "My opponent is going to win."
    :noone "No one is going to win."})

McCarthy thinks that ascribing programs beliefs can be useful. One of the reasons is that it helps us as humans, reason and debug our programs. I definitely saw the value of this when I was trying to debug my tic tac toe game. After it failed to block my winning move, I could see what its false belief was – ah – it thought that “No one is going to win”. I wrote another failing unit test to fix its bad belief.

My Tic Tac Toe Program Looks to See What Its Possible Actions and Preferences Are

It looks at the board and computes all its possible next moves. Then it computes all the possible next moves of its opponent. It looks at the consequences of these moves by assigning a belief from one of its three beliefs. Next, it ranks the moves according to the preference of its beliefs.

(def belief-action-preferences
  { (beliefs :win) 1
    (beliefs :lose) 2
    (beliefs :noone) 3})

It then chooses the move to take that has the highest rank. If it believes that no-one is going to win, I opted to have it choose a random move from the list of possible choices. But this randomness is completely arbitrary on my part and not necessary to SDFW at all.

Why ClojureScript is Awesome

I coded the core tic-tac-toe program in Clojure, but then I thought that having a web page UI would be nice for my daughter to play with. So, I just took the game logic and moved it to ClojureScript. Let me say that again slower… I used the same code on the server on the browser. Awesome. Using the lein-cljsbuild crossover support, I was able to simply configure my UI ClojureScript code to access my regular clojure game engine. Very cool. I was also very pleased to work with the https://github.com/levand/domina DOM manipulation library for ClojureScript.

End Result

It was a fun project that let me play with ClojureScript, explore McCarthy’s free will for robots, have some very interesting conversations about free will with my co-wokers and code and coffee friends, and make a game for my daughter to play and enjoy. If you are interested in checking out the program for yourself – http://gigasquid.github.com/sdfw-tic-tac-toe/. The last belief is displayed at the bottom. I have only tried it on Chrome, so beware. Finally, if you find any false beliefs, feel free to submit a pull request to https://github.com/gigasquid/sdfw-tic-tac-toe.

P.S. If you are wondering, I drew the awesome graphics all by myself.

7 John McCarthy Papers in 7 weeks – Prologue

In the spirit of Seven Languages in Seven Weeks, I have decided to embark on a quest. But instead of focusing on expanding my mindset with different programming languages, I am focusing on trying to get into the mindset of John McCarthy, father of LISP and AI, by reading and thinking about seven of his papers.

Why?

Get out of your box

If you are comfortable, you are not challenging yourself to grow. You are doomed to stay in your same mindset and your little box and your world gets smaller. As an Object Oriented programmer, I was happy in my little box. Then one day, I discovered Clojure and Functional Programming and my world became bigger and richer because of it. I hope to glean a similar box expansion, by exploring the thoughts of McCarthy. Especially, since I have the nagging suspicion that we are somehow doing programming “completely wrong.”

Slow Down

Reading papers is an antidote to today’s relentless stream of Twitter and Hacker News techno stuff. It forces you to slow down and read something …gasp, maybe even the same thing multiple times and digest it. Thinking slow and eating more veggies is something we could all do more.

Structure

Following a somewhat arbitrary schedule of seven papers in seven weeks gives a structure that gives an measurable goal and timeline to this endeavor. Which gives you a fighting chance of actually getting it accomplished.

The Answer is Never Too Far Away

When we are presented with a problem, more often then not, the answer comes to us from some of our recent thoughts and experiences. Many breakthroughs in new technologies have come from cross pollination across different fields. Exposing yourself to a new ways of thinking gives your creative problem solving abilities new and powerful ammunition.

Encourage Others

Serendipity moves in mysterious ways. By sharing your travels and thoughts, who knows what might spark in someone else’s mind…

So I encourage you to join along. Pick a paper that appeals to you and read it this week. Think about it, talk to your co-workers about it, maybe write about it, or even code from it. But most importantly, slow down and take a moment to peek outside your box.

A Clojure REPL Driven Roomba


One of the things that I love about Clojure is that it can go anywhere that Java can.  That is why, when I found out that the Roomba already had a Java library written for it – I was excited to be able to hook it up to my Emacs / Swank and be able to control it from my editor.

It is great fun! If you have a Roomba at home and you want to play along…

  1. Read Setting up and Configuring Bluetooth and Roomba part from this post.

  2. Checkout the sample project clj-roomba from github.

Have fun doing this like this:

(def roomba (RoombaCommSerial. ))
 
;;Find your port for your Roomba
(map println (.listPorts roomba))
(def portname "/dev/cu.FireFly-943A-SPP")
(.connect roomba portname)
(.startup roomba)  ;;puts Roomba in safe Mode
;; What mode is Roomba in?
(.modeAsString roomba)
(.control roomba)
(.updateSensors roomba) ; returns true if you are connected
 
 
(.pause roomba 30)
(.playNote roomba 72 40)
(.playNote roomba 79 40)
(.spinLeft roomba)
(.spinRight roomba)
(.goBackward roomba)
(.goForward roomba)
(.turnLeft roomba)
(.turnRight roomba)
 
(.stop roomba)
(.reset roomba)
(.vacuum roomba true)
(.vacuum roomba false)
(.clean roomba)
 
;; Get the sensor data
(.updateSensors roomba) 
(.bumpLeft roomba)
(.bumpRight roomba)
(.wheelDropLeft roomba)
(.wheelDropRight roomba)
(.wheelDropCenter roomba)
(.sensorsAsString roomba)
 
 
(defn bark [r]
  (doto r
    (.vacuum true)
    (.playNote 50 5)
    (.pause 150)
    (.vacuum false)))
 
(bark roomba)

A quick video of hacking Roomba in action

Next up – Getting more roombas to implement Rich Hickey’s ant colony demo

Baba Yaga and the Clojure Reducers

Baba Yaga's House

Once upon a time, a young girl decided to take a break from her code and stroll in the forest. It was quite a pleasant day, she packed her lunch in her bag and set off. While she was walking, she started thinking about a concurrency bug that her OO project was having. As she pondered the complexities of mutablilty, state, and threads, she must of strayed from the trail and lost track of time. By the time she looked around, she realized that she was totally lost.

It was then she spotted a very strange hut on chicken legs in the middle of the forest. The door was open, and there was a ladder leading up to it. She yelled “Hello”, but there was no response. She climbed up the ladder and entered the hut to see if she could find anyone inside. The hut was empty except for a pile of old books, a large kettle, and very skinny, malnourished black cat. Her heart went out to the poor cat. She took her sandwich from her bag and watched as the cat greedily ate it. The cat looked up at her and said, “Thank you for your kindness. Now, you should really get out of her before Baba Yaga …”

A large gust of wind came at the door and Baba Yaga appeared. She smiled an iron tooth grin at the girl and said, “What do we have here? An intruder!”.

The girl stammered out, “I am sorry, it is just a mistake. I am lost ..”

“Too late!” Baba Yaga grinned larger. “You are now my slave and if you don’t complete my tasks, I will eat you for my supper.” She thought for a moment and then pulled a book titled The Odyssey from the pile. “Your first task is to calculate the hash code of every character this book. Then sum of the values of only the even ones. Make sure you have it done before I return. And do it fast, I will be timing you.” Baba Yaga turned and disappeared in a gust of wind, with the door slamming and locking firmly in place behind her.

The girl sunk to the floor and started to weep. How could she complete the task? The cat rubbed up against her and purred, “You showed kindess to me where Baba Yaga never has. I will help you. It seems like this task would be best suited to a Clojure map, filter, and reduce, don’t you think?”

The girl wiped her eyes. “Cat, I think you are right.” She picked up the book. “The first thing we need is to get the content of this book into a vector.”

(def odyssey-text (vec (slurp "odyssey.txt")))
(class odyssey-text) ;=> java.lang.PersistentVector

“The vector contains all the characters. See, we can grab the first one and find its hash code this way.”

(first odyssey-text) ;=> \P
(class (first odyssey-text)) ;=> java.lang.Character
(.hashCode (first odyssey-text)) ;=> 80

“Now, all we need to do is to make a function to find the hash code and map it to the entire string.”

(defn hashcode [c] (.hashCode c))
(map hashcode odyssey-text) ;=> (80 114 ..... )

“Next, we need to filter only the even ones out.”

(defn hashcode [c] (.hashCode c))
(map hashcode odyssey-text) ;=> (80 114 111..... )
(filter even? (map hashcode odyssey-text)) ;=> (80 114 ... )

“Finally, we just need to sum all these values up with reduce.”

(reduce + (filter even? (map hashcode odyssey-text))) ;=> 33702446

As soon as she had gotten her answer, Baba Yaga appeared back through the door. “Well, you seemed to have found the answer. But, let’s see how long it took you.”

(dotimes [n 5]
  (println (str "map - filter - reduce - ( run " n " ):"))
  (time (reduce + (filter even? (map hashcode odyssey-text)))))
       ;=> map - filter - reduce - ( run 0 ):
       ;   "Elapsed time: 6932.227 msecs"
       ;   map - filter - reduce - ( run 1 ):
       ;   "Elapsed time: 5433.219 msecs"
       ;   map - filter - reduce - ( run 2 ):
       ;   "Elapsed time: 5157.45 msecs"
       ;   map - filter - reduce - ( run 3 ):
       ;   "Elapsed time: 5397.058 msecs"
       ;   map - filter - reduce - ( run 4 ):
       ;   "Elapsed time: 5224.334 msecs"

Baba Yaga chuckled “Have it done again in under 5 seconds by the time I return. I am getting hungry.”

The girl starting sobbing again. “How am I supposed to make it faster?”

The cat calmly cleaned himself and said “I have heard that Clojure has a new Reducers library that allows you to do composable, parallel, reducible functions like mapping and filtering. Try this in the namespace.”

(ns reducers.core
  (:require [clojure.core.reducers :as r]))

“The new parallel versions of map and filter have the exact same shape as the regular versions. So all we need to do is use the new reducer versions.”

(r/fold + (r/filter even? (r/map hashcode odyssey-text))) ;=> 33702446

“But, is it faster? The girl hoped.”

        ;=>   r/map - r/filter - r/fold - ( run 0 ):
        ;     "Elapsed time: 4702.766 msecs"
        ;     r/map - r/filter - r/fold - ( run 1 ):
        ;     "Elapsed time: 4617.575 msecs"
        ;     r/map - r/filter - r/fold - ( run 2 ):
        ;     "Elapsed time: 4596.329 msecs"
        ;     r/map - r/filter - r/fold - ( run 3 ):
        ;     "Elapsed time: 4636.259 msecs"
        ;     r/map - r/filter - r/fold - ( run 4 ):
        ;     "Elapsed time: 4572.804 msecs"

“No!” Baba Yaga stormed in the room. “Cat! You helped her! You mangy thing. Get out of here!” She shoved the cat out the door. “Let me look at that. I don’t believe it. I want to see the all the filtered hash values for myself.”

The cat peeked around the corner and spoke softly to the girl. “Luckily, into uses reduce.”

(into [] (r/filter even? (r/map hashcode odyssey-text))) ;=> [80 114 ... ]

While Baba Yaga was intently inspecting all the values in the vector, the cat motioned to the girl to slip out the door. Once outside, she grabbed the cat in her arms and ran as fast and as far away as she could. She was relieved to finally reach her home safely. Where she and cat lived happily for ever after writing Clojure code.

The End

For more information about Clojure Reducers
For the code on github if you want to explore yourself.
More about Baba Yaga Russian Fairy Tales.

How to include non clojars/maven clojure version in your lein project

Do you need to have a specific version of Clojure in your leiningen project that you can’t get from Clojars?

I ran into this problem when I wanted to run a sample project on Clojure’s reducers – which is not in the current Clojars version of 1.4.0.  I needed to use the most recent version, (unreleased), of 1.5.0.  These are the steps to get you running.

  • Clone the clojure git repository 
  • In the project directory – run ant to build the jar
  • Install the jar into your local maven repo

mvn install:install-file -DgroupId=org.clojure -DartifactId=clojure -Dfile=clojure-1.5.0-master-SNAPSHOT.jar -DpomFile=pom.xml

  • Now you can update your lein project.clj with

(defproject reducers "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.5.0-master-SNAPSHOT"]])

Run lein deps and you should be all set.

 

This trick also works with running leiningen projects with Datomic.  In this case – download the Datomic library and from the root directory run
 mvn install:install-file -DgroupId=com.datomic -DartifactId=datomic -Dfile=datomic-0.1.3164.jar -DpomFile=pom.xml

******* Update *******
I found out that there is already an alpha version of Clojure on Maven. So you don’t need to do the build. http://mvnrepository.com/artifact/org.clojure/clojure/1.5.0-alpha2

It would simply be
(defproject reducers "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.5.0-alpha2"]])

Getting Ready for CodeMash

Only one more day until CodeMash.  I am really looking forward to my first one.  I have heard nothing but wonderful things about this conference that brings together developers, geeks and their families for a week in January in Sandusky, Ohio.

I am also looking forward to the opportunity of presenting my “Once Upon a Time in Clojureland” talk.  It is an introduction to Clojure in a Fairy Tale format.  I am hoping to share my enthusiasm for the language and inspire others to try it out for themselves.

If you haven’t seen it, you should check out the Mashed Code Magazine.  It is full of awesome.  It also contains a piece that I wrote under my super secret identity.  Hint, it is about Monads :)

Well off to pack and get things organized.  I’ll post my full coverage in the following days …

 

 

Sunday in the Park with George and Clojure

 

Sunday Afternoon on the Island of La Grande Jatte painted by Georges-Pierre Seurat in 1884 – 1886.

Sunday Afternoon on the Island of La Grande Jatte painted by Georges-Pierre Seurat in 1884 – 1886.

 

White: a Blank Page or Canvas.

As I spent a pleasant Sunday outside doing yard work, songs from one of my favorite musicals, “Sunday in the Park with George”, came to mind. While the songs were playing in my head, my thoughts again drifted to one of my favorite programming languages, Clojure. To my surprise, I was struck by similarities between the musical, which is about the artist Geroges Seuret and his creation of one of his famous painting, and that of the functional JVM language of Clojure. Granted, musicals, art and programming languages don’t generally get discussed together, but please humor me and let me elaborate. Following the thread of my inspiration, I will be using the first few opening lines from the musical as my headings and guides for my discussion.

Let’s start with the broad subjects of Art and Software. They are both created. We use our tools, palettes and techniques to create representations of the world. The visual artist portrays this representation in paints and on canvas, while the software developer uses programming languages and computers.

Looking back in time, we see that there are many different styles of painting that have developed over time. From flat, idealized Byzantine Art to that of the incredible realistic detail of Renaissance Dutch portrait masters. These styles were a reflection of not only the techniques and materials of the time, but also an outlook on the world and the way the artist represented it. Likewise, software styles also have differed over time. From the procedural BASIC language to the current dominant style of Object Oriented programming, the styles are a reflection of not only the technology available to us, but in the way that we model real world concepts and processes into the digital space.

The Challenge: Bring Order to the Whole.

Georges Seuret was interested in the optic effect when two small points of different color placed close to one another, would seem to create a third new and luminous color when viewed at a distance. He innovated a technique called pointillism, and created a whole painting composed of tiny dots of color. The striking effect of this can be seen in his famous, large scale painting titled “A Sunday Afternoon on the Island of La Grande Jatte”.

In his use of pointillism, Seuret turned to simplicity to create order and achieve complexity. By breaking the painting down into the essence of dots of colors, he opened the way for a sort of parallelism in color viewing by the user, which ended up giving the viewer a perception of richer colors. This very technique, enhanced by todays technology is of course the basis of our incredible RGB viewing in our televisions and monitors.

Let’s turn to Clojure. Clojure is a functional language that is interested with concurrency. It also turns to simplicity to achieve complexity. By breaking things down and simplifying to more pure functions with immutable data structures, it make the complex problem of parallel programming possible. This is something that is very hard in the Object Oriented world view programming model. In my opinion, Clojure’s approach to concurrent complexity with simplicity is an important innovation to our world of software, just as pointillism was to the world of art. To better explain, let’s walk though some of the language features.

Through Design

Rich Hickey designed Clojure as a general-purpose language. He wanted it to combine some of best parts of a scripting language – the approachability and interactive development with a REPL – with an infrastructure that would be fast, robust and support multithreaded programming.

Composition

The language itself is a LISP. It gains the benefits of the simplicity of syntax of the code as data as well as having the power of Macros that allows one to customize the language. The beauty of this simplicity and conciseness allows one to focuses more on the code that matters.

Tension

Pure functions and immutable state is great, but to most things you will need some sort of state. Clojure also provides ways to use mutable state and still support correct multithreaded designs. It uses Software Transaction Memory System and Agents to achieve this. This use of mutable state in a controlled and isolated way, allows clean, efficient and concurrent programming.

Balance

Clojure embraces the JVM as it’s platform. This pragmatic approach gives not only gives the language a scalable, proven run time environment, it also gives it the advantage of accessing Java’s many mature libraries through wrapper free interoperability.

Light

Clojure language is a joy to learn. Being concise and a LISP, is very regular in it’s syntax. There are only a few key data structures and forms to learn to really get started.

and Harmony.

Clojure has an awesome community. The level of enthusiasm and innovation among the Clojure open source developers is inspiring. Every day seems to bring a new development or contribution. There is ClojureScript for JavaScript development, Noir for web development, Logic programming just to name a few.

In summary, innovation in art and technology can come through a quest for simplification. This very act of simplification, then allows for breakthroughs in complexity. Both Seuret and Hickey have shared in this vision in both their art and software.

Finally, I highly recommend watching “Sunday in the Park with George” if you haven’t seen it yet. I also highly recommend looking at Clojure too. In fact, you might want to try some Clojure Koans before watching the show. You might enjoy it from a different perspective…