This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn successor [cell] | |
(condp = (living-neighbor-count cell) | |
3 (vivified cell) | |
2 (if (living? cell) | |
(vivified cell) | |
(killed cell)) | |
(killed cell)) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(pending border unborder | |
living? living-neighbor-count killed vivified) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn world [] | |
(println "executing root binding") | |
"root value") | |
(defn f [ignored-value] | |
(println "within f, world at" world "produces" (world)) | |
(world) | |
) | |
(println "Root world function is at" world) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(know "how living neighbors are counted" | |
(living-neighbor-count ...center...) => 1 | |
(provided | |
(neighbors ...center...) => [ ...living-cell... ...dead-cell... ] | |
(living? ...living-cell...) => true | |
(living? ...dead-cell...) => false) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn living-neighbor-count [cell] | |
(count (filter living? (neighbors cell))) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(know "that neighbors are constructed from coordinates alone" | |
(neighbors (cell-at 3 88) => (have-coordinates | |
[2 89] [3 89] [4 89] | |
[2 88] [4 88] | |
[2 87] [3 87] [4 87]) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (def product (cartesian-product [-1 0 1] [-1 0 1])) | |
#'user/product | |
user=> product | |
((-1 -1) (-1 0) (-1 1) (0 -1) (0 0) (0 1) (1 -1) (1 0) (1 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (def meaningful-values (remove #{ [0 0] } product)) | |
#'user/meaningful-values | |
user=> meaningful-values | |
((-1 -1) (-1 0) (-1 1) (0 -1) (0 1) (1 -1) (1 0) (1 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (#{1} 1) | |
1 | |
user=> (#{1} 0) | |
nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (def cell [3 88]) | |
#'user/cell | |
user=> (defn shifter [[x-shift y-shift]] [ (+ (first cell) x-shift) | |
(+ (second cell) y-shift)]) | |
#'user/shifter | |
user=> (shifter [-1 1]) | |
[2 89] | |
user=> (map shifter meaningful-values) | |
([2 87] [2 88] [2 89] [3 87] [3 89] [4 87] [4 88] [4 89]) |