Services & Resources / Wolfram Forums
MathGroup Archive
*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
  • Subject: [mg65205] Re: [mg65193] A Reap Sow question
  • From: Andrzej Kozlowski <akoz at>
  • Date: Fri, 17 Mar 2006 05:45:45 -0500 (EST)
  • References: <>
  • Sender: owner-wri-mathgroup at

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++]]]]


> 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++]]]];


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&)]]]


but that really depends on what you want to achieve which I can't  
make out from your question.

Andrzej Kozlowski

  • Prev by Date: Re: Different font behavior between kernel and front-end
  • Next by Date: Re: Subscripted variables and function definitions
  • Previous by thread: A Reap Sow question
  • Next by thread: Re: A Reap Sow question