Re: Display[ ] renewed?
- To: mathgroup at smc.vnet.net
- Subject: [mg90449] Re: Display[ ] renewed?
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Thu, 10 Jul 2008 06:32:00 -0400 (EDT)
- Organization: Uni Leipzig
- References: <g4v303$if1$1@smc.vnet.net> <g4vk92$9r3$1@smc.vnet.net> <g51ucq$6tu$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
Hi,
you original question was to add Print[]/CellPrint[] ..
to all statements in a Do[] loop.
and
Do[
expr = Sin[i*x];
CellPrint[expr];
CellPrint[Plot[expr, {x, 0, Pi}]], {i, 1, 3}]
would do that. However if you wish to add the CellPrint[]/Print[]
function in general, you must use the Hold[] function to modify all
your statements without evaluating it.
Regards
Jens
It would
AES wrote:
> In response to Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>:
>
> Thanks for suggestion -- but the situation is: I have a simple expr
> which, when evaluated by itself in its own cell, as a result of that
> evaluation creates and displays a certain plot.
>
> And all I'd like to do is stick that expr (or maybe a couple such
> expr's) into a simple Do loop, and have that Do loop **do what M's
> online documentation explicitly says a Do loop does!**, which is
>
> Do[expr,{i,Subscript[i, max]}]
> evaluates expr with the variable i successively taking on
> the values 1 through Subscript[i, max] (in steps of 1)
>
> thereby creating and displaying imax plots, not just 1.
>
> Does it really take "something like"
>
>> SetAttributes[DoPrint, HoldAll]
>>
>> DoPrint[body_, {i_, i1_, i2_}] := Module[{split},
>> split = Hold[body] /. CompoundExpression -> List;
>> split =
>> Flatten[split //. {Hold[{a_, b___}] :> {Hold[a], Hold[b]} ,
>> Hold[a_, b__] :> { Hold[a], Hold[b]}}];
>> split = split /. Hold[a_] :> Hold[Print[a]];
>> Do[
>> ReleaseHold[split /. i -> ii], {ii, i1, i2}
>> ]
>> ]
>
> (with 11 arcane Hold commands!!!) to make Do do what it says it does?
>
> (It was better when Show[ ] actually showed things! -- even if you did
> have to mess with an occasional DisplayFunction.)
>