(bind-func world_step
(lambda (w)
(letz ((cv 0)
(n 0)
(pending_updates:List* null))
(doloop (i (world_height w))
(doloop (j (world_width w))
(set! cv (cell_value w i j))
(set! n (cell_count_neighbors w i j))
(if (= cv 0:i8)
;; birth
(if (= n 3:i8)
(set! pending_updates (cons (CellUpdate i j 1) pending_updates)))
;; cell is dead
(if (not (or (= n 2:i8)
(= n 3:i8)))
(set! pending_updates (cons (CellUpdate i j 0) pending_updates))))))
;; do all the updates
(for-each (lambda (cu)
;; (println "performing update: x =" (tref cu 0)
;; "y =" (tref cu 1)
;; "newvalue =" (tref cu 2))
(cell_set_value w (tref cu 0) (tref cu 1) (tref cu 2)))
pending_updates)
(world_increment_generation w))))