From 4d087834cf0c9373e5a7538923607cf8d4b093a5 Mon Sep 17 00:00:00 2001 From: "Joe H. Rahme" Date: Wed, 16 Oct 2013 18:16:26 +0200 Subject: [PATCH] Updates to newer syntax --- conway.hy | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/conway.hy b/conway.hy index ae2cb4c..a8e9261 100644 --- a/conway.hy +++ b/conway.hy @@ -1,19 +1,10 @@ (import grid) -(import-from functools reduce) -(import-from operator add) - (def *world* (grid.Torus 10 10)) - -(defun sum (ns) - (reduce add ns)) - - (defun set! (world x y value) (setv (get world (, x y)) value)) - (defun get! (world x y) (get *world* (, x y))) @@ -25,7 +16,6 @@ dy [-1 0 1]) (!= (, (+ x dx) (+ y dy)) (, x y))))) - (defun step (world) (let ((new-world (.copy grid.Torus world))) (for (x (range new-world.width)) @@ -33,11 +23,11 @@ (let ((cell (get! new-world x y)) (ns (neighbours world x y))) (if (= cell 1) - (cond ((< ns 2) (set! new-world x y 0)) - ((or (= ns 2) (= ns 3)) (set! new-world x y 1)) - ((> ns 3) (set! new-world x y 0))) - (cond ((= ns 3) (set! new-world x y 1)) - (True (set! new-world x y 0))))))) + (cond [(< ns 2) (set! new-world x y 0)] + [(or (= ns 2) (= ns 3)) (set! new-world x y 1)] + [(> ns 3) (set! new-world x y 0)]) + (cond [(= ns 3) (set! new-world x y 1)] + [True (set! new-world x y 0)]))))) new-world))