Skip to content

Instantly share code, notes, and snippets.

View simon-brooke's full-sized avatar
💭
Semper in faecibus sumus, sole profundam variat.

Simon Brooke simon-brooke

💭
Semper in faecibus sumus, sole profundam variat.
View GitHub Profile
@simon-brooke
simon-brooke / my-cons.clj
Last active August 14, 2019 22:43 — forked from Solaxun/my-cons.clj
Clojure Cons Cell
(def NIL (symbol "NIL"))
(deftype ConsCell [CAR CDR]
clojure.lang.ISeq
(cons [this x] (ConsCell. x this))
(first [this] (.CAR this))
;; next and more must return ISeq:
;; https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/ISeq.java
(more [this] (if
(= (.CDR this) NIL)
(ns game-of-life.core)
(def world [[2 1] [2 2] [1 1]])
(defn neighbours [[x y]]
[[(dec x) (dec y)] [x (dec y)] [(inc x) (dec y)]
[(dec x) y] [(inc x) y]
[(dec x) (inc y)] [x (inc y)] [(inc x) (inc y)]])
(neighbours [2 2])