>
> I ported a Clojure implementation of Conway's Game of Life to Factor.
> Here is the original Clojure version:
> http://clj-me.cgrand.net/2011/08/19/conways-game-of-life/
> Here is my Factor port: http://paste.factorcode.org/paste?id=2932
> How can I make the Factor variant more elegant and/or idiomatic?
>

Some ideas:

1) Your "frequencies" word is the same as "histogram" in math.statistics
vocabulary.

2) Your calculation of neighboring cells could use a constant to represent
the 8  adjacent cells, instead of computing it each time:

CONSTANT: coordinates {
    { 1 1 }
    { 1 0 }
    { 1 -1 }
    { 0 1 }
    { 0 -1 }
    { -1 1 }
    { -1 0 }
    { -1 -1 }
}

: neighbours ( loc -- neighbours )
  coordinates [ v+ ] with map ;

3) you might try factoring out the steps in "steps", perhaps something like
this:

: count-cells ( cells -- counts )
    [ neighbours ] map concat histogram ;

:: live? ( loc count cells -- ? )
    count 3 = [ t ] [ count 2 = loc cells in? ] if ;

:: steps ( cells -- cells' )
    cells count-cells [ cells live? ] assoc-filter keys ;
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and 
their applications. This 200-page book is written by three acclaimed 
leaders in the field. The early access version is available now. 
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to