|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Aaron,
Very cool example you gave. I'd make some changes to the way you
implemented the game to make it more functional & idiomatic Clojure
* Use a vector of vectors stored in an agent for env, not a 2D java
array. This is a little slower, but mutating arrays in place is not a
good example for beginning Clojure. I'll refer to this vector of
vectors as a "board"
* The run fn should take a board in, and return a board one step
later. This fits in with Clojure's built in stuff better (see below)
* Trim down alive & dead cell rules, and use get w/ a default. i.e.
user=>(defn dead-rule [neigh]
(get {3 resurrect-cell} neigh kill-cell))
user=>(defn alive-rule [neigh]
(get {2 resurrect-cell
3 resurrect-cell}
neigh kill-cell))
There might even be more to trim.
* use iterate with run to create a lazy seq, or send w/ and agent
user=>(iterate step board-start)
user=>(send step board-agent)
* decouple the printing from the run fn. Using an agent will really
help with this, and make it easier to graft some Swing/SWT/whatever on
later.
I'll put my money where my mouth is and code up my implementation when
I have time. We'll see how much snow we get this weekend.
Sean
On Feb 5, 2:02 pm, Aaron Feng <aaron.f...@gmail.com> wrote:
> Sebastian mentioned in the previous thread about code retreat. Here's
> my implementation in Clojure:http://github.com/aaronfeng/game-of-life/blob/master/life.clj
>
> I think it's a pretty interesting implementation. Feedback are welcomed.
>
> Aaron
|
|