MathGroup Archive 2009

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

Search the Archive

Re: Re: Show doesn't work inside Do loop ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102024] Re: [mg102013] Re: Show doesn't work inside Do loop ?
  • From: danl at wolfram.com
  • Date: Mon, 27 Jul 2009 05:53:18 -0400 (EDT)
  • References: <32390795.1248259308283.JavaMail.root@n11>

> [...]
> 2)  On a more general note:  Suppose you have an expression which
> contains an explicit symbol x , such that if you execute three
> consecutive cells containing
>
>    x=1; expr
>    x=2; expr
>    x=3; expr
>
> or maybe
>
>    expr/.x->1
>    expr/.x->2
>    expr/.x->3
>
> you get three output cells containing three successive instances of expr
> (whatever that is) -- or appropriate error messages if executing expr
> one of those times has some side effect that messes up a subsequent
> execution.
>
> Would it not be reasonable to expect a cell containing
>
>    Do[ expr, {x,1,3} ]
>
> to do _exactly_ the same thing?
>
> In other words, would it not be reasonable -- consistent -- sensible --
> helpful -- the most useful -- to expect Do[ ] to be simply a "wrapper"
> that functioned in exactly that manner?
> [...]

It would not.

Do "does", that is, evaluates it's argument each iteration, and returns
Null. There is nothing else it can plausibly return. A better analogy to
Do would be

expr/.x->1;
expr/.x->2;
expr/.x->3;


> I appreciate that Mathematica's Do[] apparently doesn't function that
> way -- or functions that way sometimes, based on mysterious criteria,
> but not other times; and suggest that this is not helpful or useful or
> consistent behavior for many users.
>
> Are there any fundamental reasons why a DoConsistently[ ] command could
> not be defined, such that DoConsistently[ expr, iterator ]  would
> repeatedly put expr into a cell with each iterator instance applied to
> it, and churn out the sequential outputs?  That, it seems to me, is what
> many users would want and expect.

I imagine something like this could be coded (but probably not by me).
Bear in mind that it would have semantics that depend on the interface,
and in particular would be different in a terminal interface vs. the
Mathematica front end. In other words, it would be more a user interface
function than a kernel evaluation function. I'm not convinced this would
be a good thing to have.

Daniel Lichtblau
Wolfram Research





  • Prev by Date: Re: Mathematica Animations by High School Students
  • Next by Date: Re: Re: solving a system of two equations
  • Previous by thread: Re: Re: Show doesn't work inside Do loop ?
  • Next by thread: Re: Re: Show doesn't work inside Do loop ?