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: [mg65205] Re: [mg65193] A Reap Sow question
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Fri, 17 Mar 2006 05:45:45 -0500 (EST)
  • References: <200603170513.AAA09771@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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





  • 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