Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: A Reap Sow question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65216] Re: [mg65193] A Reap Sow question
  • From: János <janos.lobb at yale.edu>
  • Date: Sat, 18 Mar 2006 06:40:38 -0500 (EST)
  • References: <200603170513.AAA09771@smc.vnet.net> <4EF26559-3634-461D-9E5E-6522C06A6751@mimuw.edu.pl>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Andrzej,

Yes, you are right.  I thought of the i++ and that was so satisfying  
for me that I did not write it down :)  It is like attending to go  
through the Universe to get the magic key to the Princess's heart,  
but really never blast off from the ground, because I already did  
steal the only key to it from the secret room.

Well, me being a "paleface", let me reformulate my thoughts.

We all know that there is a  Cornu spiral connecting the houses of  
the two world known constructors Trurl and Klapaucius.  Turl is  
making his evolving time capsules and as soon as he does one, he sets  
it on its feet and gives a gentle bang on the back to start marching  
on the road to the direction of Klapaucius's house.  Of course Trurl  
does not want to anger Klapaucius with cookie cutter time capsules -  
that is why he calls them the "evolving" ones -, so he Sow some extra  
parts into them before sending them on their way.   As the capsules  
are marching on the road - first around his house a few times - Trurl  
periodically reaches out to them to get back the now evolved extra  
parts to put into the newly assembled evolving time capsule.
At the end of the road Klapaucius is Reaping all the time capsules  
and he is putting them through a rigorous quality inspection, because  
he knows that when Trurl decides to create evolving time capsules,  
some Big Bangs can happen if one is not careful enough.

So, my situation is similar to Trurl's.  Right now I am appending to  
a list  and as I am adding more and more items to it by using  
AppendTo, I have to pull back some earlier members of the list,  
because they are needed to create the new members of the list.  This  
method works satisfactory for the first 60 - 80 members of the list  
and my G5 duo core constructor - although it is NOTHING compared to  
Trurl - is happy to churn out them in less than a minute.  As soon as  
I have about 110 items, it takes half an hour to put one new item  
into it.  So I was thinking to give up on AppendTo and use Reap Sow  
to collect the list elements, but on the same time I needed to look  
into the list for earlier elements, because I needed them for  
construction.

With the best,

János


On Mar 17, 2006, at 5:03 AM, Andrzej Kozlowski wrote:

>
> On 17 Mar 2006, at 06:13, János wrote:
>
>>
>> Let say I have a construct like
>>
>> collection=Reap[i=1; While[i<=10,Sow[i]];]
>
> Looks like one of those journeys that take infinitely long yet  
> never leave the starting point. Again something out of Lem? ;-)
> Presumably you meant:
>
> collection = First[Last[Reap[i = 1; While[i <= 10, Sow[i] ;i++]]]]
>
> {1,2,3,4,5,6,7,8,9,10}
>
>>
>> Is it possible to put a condition on Sow referring back to
>> collection ?  Something like:
>>
>> collection=Reap[i=1; While[i<=10,If[Length[First[Last[collection]] ]
>>> 5,,Sow[i] ] ];]
>
>
> It seems obvious that you can't  since "collection" won't have any  
> value until you Reap what you have Sown.
>>
>> If not, - I have not seen any indication in Help either way - , what
>> technique can be used to get a similar effect without resorting to
>> global lists or arrays?
>>
>
> What do you mean by " a similar effect"? Is this a "similar effect":
>
> collection = First[Last[
>     Reap[i = 1; While[i <= 10, If[i <= 5, Sow[i]]; i++]]]];
>
> {1,2,3,4,5}
>
> More seriously, probably you can make use of tags in Sow and Reap  
> as in
>
>
> Flatten[Last[  Reap[i = 1; While[i <= 10,  Sow[i,i]; i++],_?(#<=5&)]]]
>
> {1,2,3,4,5}
>
> but that really depends on what you want to achieve which I can't  
> make out from your question.
>
> Andrzej Kozlowski
>
>
>



--------------------------------------------------
Lunatics always attain their goals better than normal people do. It  
happens because there are no moral boundaries for them: no shame, no  
truthfulness, no conscience, and not even fear.    <Leo Tolstoy>


  • Prev by Date: Re: Is this a BUG of D[f, var1, ..., NonConstants -> {u1, ...}] ?
  • Next by Date: Re: Re: variance of difference sign test
  • Previous by thread: Re: A Reap Sow question
  • Next by thread: Re: Re: A Reap Sow question