As you see at the bottom of this, I am in the process of debugging this.
?(?-) (An implementation of conway's game of life Incomplete.) ?(?-) (I have the sense that I'm dancing around some very simple thing here, which is why there's so much.) ?(?-) (Applicative order rules) <> ((?x) (?y) <=!=>) (<> ?x ?y) <> ((?x) ?. <=!=>) (<> ?x (?.)) <> (?x ?y <=!=>) (<> ?x ?y) <> (<!> ?x ?y) ((?x) (?y) ?(?x ?x) <=!=>) ?(?-) (Evaluate left-hand-side of rule only) <> ((?x) <=!=< (?y)) (<> ?x ?y) <> ((?x) <=!=< ?. ) (<> ?x (?.)) <> (?x <=!=< ?y) (<> ?x ?y) <> (<!< ?x ?y) ((?x) ?(?x ?x) <=!=< (?y)) ?(?-) (Applicative-order lambdas) <> ((?l ?r) ?. <=!@=>) (?(?l ?r) ?.) <> (<!@> (?l ?r) ?x) ((?l ?r) ?x ?(?z ?z) <=!@=>) ?(?-) (Function application) <> (?. <=$=> ?f) (?f ?.) <> ((?a) <=$=> ?f) (?f ?a) <> (<$> ?f ?a) (?a ?(?x ?x) <=$=> ?f) <> $screen-size ((16)) <> $board-offset ((4)) <!> $board-size (($screen-size ($board-offset (2) `*) `-)) <> $live-color ((#ffffff)) <> $dead-color ((#000000)) ?(?-) (Utils) <> (!random) (?((?: ?0 ?1) ?:) rand 0 2) <> (eq (?x ?x)) #t <> (eq (?x ?y)) #f <> ((?0) (?1) `?:) ?: <> (?x -1) ((?x) (1) `-) <> (?x +1) ((?x) (1) `+) <> (read ?: (point ?0 ?1) (?2)) ?: <> (read ?: (?0 ?1) (?2)) ?: <> (draw ?: (point ?0 ?1) (?2)) ?: ?(?-) (Initialize the game board) <!> (?p (0) cell) (draw pixel ?p $dead-color) <!> (?p (1) cell) (draw pixel ?p $live-color) <> (handle-event (Tic ?x)) (Conway) <> (handle-event ?x) (?(?: ?:) (print (Unknown event: ?x \n))) <> (on-event ?~) (handle-event ?~ on-event Any) <!< ($board-offset $board-offset init) () <!< ($board-offset (?j) init) ($board-size ((?j) (1) `-) init) <> ((?i) (?j) init) ( (point ?i ?j) ((0) (2) `rand) cell ((?i) (1) `-) (?j) init ) <!@> (((?0) (?1) ?:) ?:) ($screen-size $screen-size size) <!@> ((?0 ?1 (?2) (?3) ?4 ?:) ?:) (0 0 $screen-size $screen-size #ff0000 rect) ?(?-) ($board-size $board-size init) ?(?-) (Conway stuff. We can do standard arithmetic on hexadecimal values.) <!> (judge $live-color ($live-color (#000002) `*)) $live-color <!> (judge $live-color ($live-color (#000003) `*)) $live-color <!> (judge $dead-color ($live-color (#000003) `*)) $live-color <!> (judge (?c) (?d)) $dead-color ?(?-) (Let's get an incorrect version going first) <> (Conway) ($board-size $board-size row-to-ram $board-size $board-size Iterate) <!< ($board-offset $board-offset Iterate) () <!< ($board-offset (?y) Iterate) ($board-size ((?y) (1) `-) row-to-ram $board-size ((?y) (1) `-) Iterate) <> ((?x) (?y) Iterate) ( copy (0 0) (1 0) copy (?x ?y) (0 0) (at ?x ?y it's (read @pixel (?x ?y) (#000000)) (sum-neighbors-of ?x ?y)) draw pixel (point ?x ?y) (judge (read @pixel (?x ?y) (@000000)) (sum-neighbors-of ?x ?y)) ((?x) (1) `-) (?y) Iterate ) ?(?-) (Operations) <> (``?: (?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7)) ?: <!< (sum-neighbors-of ?x $board-size) ( ``+ (read @pixel ((?x) (1) `- (?y) (1) `-) (#000000) read @pixel ( ?x (?y) (1) `-) (#000000) read @pixel ((?x) (1) `+ (?y) (1) `-) (#000000) read @pixel ((?x) (1) `- ?y) (#000000) read @pixel (1 0) (#000000) #000000 #000000 #000000) ) <> (sum-neighbors-of ?x ?y) ( ``+ (read @pixel ((?x) (1) `- (?y) (1) `-) (#000000) read @pixel ( ?x (?y) (1) `-) (#000000) read @pixel ((?x) (1) `+ (?y) (1) `-) (#000000) read @pixel ((?x) (1) `- ?y) (#000000) read @pixel (1 0) (#0) read @pixel ((?x) (1) `- 0) (#000000) read @pixel ( ?x 0) (#000000) read @pixel ((?x) (1) `+ 0) (#000000)) ) <> (copy (?a ?b) (?c ?d)) ( draw pixel (point ?c ?d) (read @pixel (?a ?b) (#000000))) <!> ($board-offset (?r) row-to-ram) () <> ((?x) (?r) row-to-ram ) (copy (?x ?r) (?x 0) ((?x) (1) `-) (?r) row-to-ram) ?(?-) ( on-event Any $board-size $board-size Iterate ) ?(?-) (Try starting with a simple oscillator) draw pixel (point 0 0) (#000000) draw pixel (point 1 0) (#000000) draw pixel (point 5 6) (#ffffff) draw pixel (point 6 6) (#ffffff) draw pixel (point 7 6) (#ffffff) $board-size (1) row-to-ram ?(?-) ( copy (0 0) (1 0) copy (?x ?y) (0 0) draw pixel (point ?x ?y) (judge (read @pixel (?x ?y) (#000000)) (sum-neighbors-of ?x ?y)) draw pixel (point 1 0) (#000000) read @pixel (7 7) (#000000) sum-neighbors-of 7 7 read @pixel (6 7) (#000000) sum-neighbors-of 6 7 read @pixel (5 7) (#000000) sum-neighbors-of 5 7 ) ?(?-) ( We're drawing a grid like this: [ this is (5 5) -> - - - - # # # - - - - - - - - - this is (8 8) ---------^ ] We would expect that the first pass would look like this: (at 8 8 it's (#000000) (0)) (at 7 8 it's (#000000) (0)) (at 6 8 it's (#000000) (0)) (at 5 8 it's (#000000) (0)) (at 8 7 it's (#000000) (16711680)) (1 neighbor) (at 7 7 it's (#000000) (33554430)) (2 neighbors) (at 6 7 it's (#000000) (50331645)) (3 neighbors) (at 5 7 it's (#000000) (33554430)) (2 neighbors) (at 8 6 it's (#000000) (16711680)) (1 neighbor) (at 7 6 it's (#ffffff) (16711680)) (1 neighbor) (at 6 6 it's (#ffffff) (33554430)) (2 neighbors) (at 5 6 it's (#ffffff) (16711680)) (1 neighbor) (at 8 5 it's (#000000) (16711680)) (1 neighbor) (at 7 5 it's (#000000) (33554430)) (2 neighbors) (at 6 5 it's (#000000) (50331645)) (3 neighbors) (at 5 5 it's (#000000) (33554430)) (2 neighbors) Instead we have something fucking crazy like this: (at 8 8 it's (#000000) (16711680)) (at 7 8 it's (#000000) (0)) (at 6 8 it's (#000000) (0)) (at 5 8 it's (#000000) (16711680)) (at 8 7 it's (#000000) (33488895)) (at 7 7 it's (#000000) (33554430)) (at 6 7 it's (#000000) (50331645)) (at 5 7 it's (#000000) (50266110)) (at 8 6 it's (#000000) (50266110)) (at 7 6 it's (#ffffff) (50331645)) (at 6 6 it's (#ffffff) (83886075)) (at 5 6 it's (#ffffff) (67043325)) (at 8 5 it's (#000000) (33488895)) (at 7 5 it's (#000000) (0)) (at 6 5 it's (#000000) (0)) (at 5 5 it's (#000000) (16711680)) (at 8 4 it's (#000000) (16711680)) (at 7 4 it's (#000000) (0)) (at 6 4 it's (#000000) (0)) (at 5 4 it's (#000000) (16711680)) ) Conway