MathGroup Archive 2009

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

Search the Archive

Re: Do-command

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102647] Re: [mg102588] Do-command
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Mon, 17 Aug 2009 04:31:46 -0400 (EDT)
  • References: <200908161038.GAA01118@smc.vnet.net>

Hi Uwe,

Do is not supposed to produce any output by itself (it produces Null).
You should either use side effects (assignments) to save your results,
or use a different programming style (such as functional programming).
You can also use Reap and Sow.
If I understand correctly what you really want, it can be achieved by

In[1] = Map[Function[x, Select[{1, 2, 4, 7, 6, 2}, # >= x &]], Range[7]]

Out[1] = {{1, 2, 4, 7, 6, 2}, {2, 4, 7, 6, 2}, {4, 7, 6}, {4, 7, 6}, {7,
  6}, {7, 6}, {7}}

With Reap and Sow, you will get it in this way:

In[2] = Reap[Do[Sow[Select[{1, 2, 4, 7, 6, 2}, # >= i &]], {i, 7}]][[2, 1]]

Out[2] = {{1, 2, 4, 7, 6, 2}, {2, 4, 7, 6, 2}, {4, 7, 6}, {4, 7, 6}, {7,
  6}, {7, 6}, {7}}


Regards,
Leonid


On Sun, Aug 16, 2009 at 2:38 PM, Uwe Gotzes <u.gotzes at googlemail.com> wrote:

> Hi!
>
> Can anybody tell, why
> Do[Select[{1, 2, 4, 7, 6, 2}, # >= i &], {i, 7}]
> does not produce output in Mathematica?
>
>



  • References:
    • Do-command
      • From: Uwe Gotzes <u.gotzes@googlemail.com>
  • Prev by Date: Re: Generating a list numnber in string format
  • Next by Date: Re: Is it possible with Mathematica?big problem.thank you
  • Previous by thread: Re: Do-command
  • Next by thread: Re: Do-command