Thank you, John. That's what I was looking for.

I must say: currying an entire sequence is pretty wild! It's a non-obvious
solution.

>> "I'm not sure that is undesirable here...?"

No, it's not undesirable, except for the fact that 30-40% of that code
exists for the sake of the side-effect.

Of course, computation by calculation is shorter again ...

USING: arrays math math.ranges math.primes.factors sequences ;
IN: lamps

: <people> ( -- seq )
    100 [1,b] >array ;

: calc-switching ( -- lamps )
    <people> [ divisors length even? ] map ;


(But then, that wasn't my purpose. I was trying to figure out how to get a
nested iteration done with sequences instead of always falling back to
recursion.)

Thanks, again.

Loryn Jenkins



On Tue, Apr 23, 2013 at 12:44 AM, John Benediktsson <mrj...@gmail.com>wrote:

> Something like this would be simpler:
>
> http://paste.factorcode.org/paste?id=2914#1329
>
> You don't need a symbol to pass the variable around, and even though it is
> "side-effecting", I'm not sure that is undesirable here...?
>
>
> On Mon, Apr 22, 2013 at 7:17 AM, Loryn Jenkins <lor...@gmail.com> wrote:
>
>> Hi
>>
>> In "Factor Philosophy", slava writes: "Imperative programming and indexed
>> loops are almost always not the most idiomatic solution."
>>
>> I've implemented this puzzle (
>> http://mindyourdecisions.com/blog/2013/04/22/100-light-bulbs-puzzle/ )
>> using a side-effecting function:
>> http://paste.factorcode.org/paste?id=2914
>>
>> The words do-switching and toggle-switches implement the equivalent of a
>> nested loop.
>>
>> Without using recursion, counted for loops or side-effecting functions,
>> what is an idiomatic way of implementing this nested iteration?
>>
>> Loryn Jenkins
>>
>>
>> ------------------------------------------------------------------------------
>> Precog is a next-generation analytics platform capable of advanced
>> analytics on semi-structured data. The platform includes APIs for building
>> apps and a phenomenal toolset for data science. Developers can use
>> our toolset for easy data analysis & visualization. Get a free account!
>> http://www2.precog.com/precogplatform/slashdotnewsletter
>> _______________________________________________
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>>
>
>
> ------------------------------------------------------------------------------
> Precog is a next-generation analytics platform capable of advanced
> analytics on semi-structured data. The platform includes APIs for building
> apps and a phenomenal toolset for data science. Developers can use
> our toolset for easy data analysis & visualization. Get a free account!
> http://www2.precog.com/precogplatform/slashdotnewsletter
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to