Still working on the Shut the Box program in Scheme / Racket, and I'm getting stuck.
I know that mutable global values are bad (m'kay) but I'm not sure how to pass the values along in some meaningful way. Perhaps it's all of the years of object oriented programming shining through but I'm thinking of two dice in a roll-object where those get passed along until the tiles are flipped and the next roll is thrown.
Thoughts on how to make this more functional are welcome.
#lang racket #| Init Block |# (define tiles '()) (define die1 0) (define die2 0) (define (start-game) (set! tiles '(1 2 3 4 5 6 7 8 9))) (define (dice) (+ 1 (random 6))) (define (dice-roll) (set! die1 (dice)) (set! die2 (dice))) (define (sum-of-dice die1 die2) (+ die1 die2)) (define (shut-tiles tilelist) (for ([i tilelist]) (if (index-of tiles i) (set! tiles (remove i tiles)) (print "Tile already shut")))) (start-game) (dice-roll) (define (next-turn) (dice-roll) (show-turn)) (define (show-turn) (println tiles) (printf "Dice roll ~v ~v = ~v" die1 die2 (sum-of-dice die1 die2) ))