Hi Björn,

Thanks for responding. Although I am used to seeing Life
representations as X by Y matrices, that wasn't the part I had trouble
with. My problem was much more mundane - I forgot the outside braces!
Their necessity seems obvious in retrospect. Looking back at the
Clojure example, I see that they were even there, although, of course,
one can't assume similar syntax between these two languages. Thanks
also for your more visual version of the program.

I'm going to take this opportunity to campaign for usage examples.
Björn's initial simple example cleared things up for me immediately.
Likewise, when I'm learning new Factor words and vocabularies, I go
straight to the "*-tests.factor" file, if it exists, to see how to use
the words. In my perfect Factor world, test files would be mandatory
(and all Factor documentation would include usage examples)! John
Benediktsson's entertaining "Re: Factor" blog is also enlightening
because he almost always (always? - the absolute is hard to prove)
includes examples of how to use the words he's creating. It may be
obvious to the creator of new Factor words at the time of their
creation how they are intended to be used, but a few simple examples
can make things a lot easier to understand for the rest of us.

By the way, this is in no way meant to criticize Kabelo's original
post. He was seeking guidance, not striving to instruct. However, with
a few examples he could have done both!

-John

On Mon, Jun 3, 2013 at 12:44 PM, Björn Lindqvist <bjou...@gmail.com> wrote:
> Hi,
>
> The really smart and non-obvious thing about the Clojure code is that it
> represents the board as a set of coordinates to the alive cells. A naive
> solution would probably have used a two-dimensional array of size XxY with
> the values t for live cells and f for dead ones. Was that part what confused
> you? So, if you have the code loaded in Factor (use Emacs and FUEL so that
> you can easily experiment) test it like this:
>
> IN: scratchpad { { 1 0 } { 1 1 } { 1 2 } } step
> { { 1 1 } { 0 1 } { 2 1 } }
> IN: scratchpad { { 1 0 } { 1 1 } { 1 2 } } step step
> { { 1 1 } { 1 0 } { 1 2 } }
>
> IN: scratchpad is the prompt, the code after is what you should type. Note
> that the last expression evaluates to the input argument which proves that
> the pattern oscillates. Here is an extension to the program with nicer
> output so that one can see what is going on:
>
> http://paste.factorcode.org/paste?id=2963
>
> IN: scratchpad USE: life
> IN: scratchpad 3 20 run-life
> ---
> ...*..*.
> .....*.*
> ....*..*
> ..**.*..
> ....*.*.
> *.*.*...
> ..*.*...
> .*..*..*
> ---
> ......*.
> ....**.*
> ..*..*..
> ..**.**.
> .*......
> .*..*...
> ..*.**..
> ...*....
> ---
> .....**.
> ....**..
> ..*.....
> .******.
> .*.***..
> .*****..
> ..*.**..
> ...**...
> IN: scratchpad
>
>
> 2013/6/3 John Porubek <jporu...@gmail.com>
>>
>> At the risk of exposing my ignorance, how would I test this? I assume
>> there's an analog to the Clojure example, but it's exact nature escapes me!
>> Any help appreciated.
>>
>> -John
>>
>>
>> On Sun, May 12, 2013 at 1:00 PM, John Benediktsson <mrj...@gmail.com>
>> wrote:
>>>>
>>>> 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
>>> Factor-talk@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Get 100% visibility into Java/.NET code with AppDynamics Lite
>> It's a free troubleshooting tool designed for production
>> Get down to code-level detail for bottlenecks, with <2% overhead.
>> Download for free and get started troubleshooting in minutes.
>> http://p.sf.net/sfu/appdyn_d2d_ap2
>>
>> _______________________________________________
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>
>
>
> --
> mvh/best regards Björn Lindqvist
> http://www.bjornlindqvist.se/
>
> ------------------------------------------------------------------------------
> Get 100% visibility into Java/.NET code with AppDynamics Lite
> It's a free troubleshooting tool designed for production
> Get down to code-level detail for bottlenecks, with <2% overhead.
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap2
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to