Skip to content

Instantly share code, notes, and snippets.

@aepyornis
Last active October 5, 2015 14:32
Show Gist options
  • Save aepyornis/6a00e4e7c4f36bfc0972 to your computer and use it in GitHub Desktop.
Save aepyornis/6a00e4e7c4f36bfc0972 to your computer and use it in GitHub Desktop.

A tour of clojure(script) syntax.

Perhaps you will or won't find this interesting, but I think clojure provides some compelling form to work with. I've essentially just going over the bits that are different from languages we are used to, like javascript. Anyways, it's just help for me to write this all down.

data structures: There are are immutable, which is part of the big selling point of clojuire.

Maps:

{:a 1
:b "some text"
:c [] }

;; to change a proberty you use (assoc) which returns a new map. It can either defined an old key or add a new one.

(assoc {:a 1 :b "sometext"} :a 4) ;; => {:a 4 :b "sometext"}
(assoc {{:a 1 :b "sometext"} :c "value");; => {:a 1, :b "sometext", :c "value"}

This basic map is called a 'hash-map'. Instead of using {} to recate it you can called the function (hash-map). There's also some variations on maps in clojure inluding a sorted-map and array-map.

Other than it being immutable, it's similar to objects in javasript, except it's not used to store functions like you do in javascript. So

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment