Re: Re: Show doesn't work inside Do loop ?
- To: mathgroup at smc.vnet.net
- Subject: [mg101975] Re: [mg101973] Re: Show doesn't work inside Do loop ?
- From: "David Park" <djmpark at comcast.net>
- Date: Sat, 25 Jul 2009 04:15:39 -0400 (EDT)
- References: <32390795.1248259308283.JavaMail.root@n11> <h4951e$q2e$1@smc.vnet.net> <21621663.1248432817472.JavaMail.root@n11>
AES, I have to admit that this is a source of confusion and there have been a number of questions on MathGroup about it. I had to look more carefully at the documentation to better understand it and not see it just as a "feature". >From the Print Function page: "In a notebook, Print generates a cell with style "Print"." I believe CellPrint could also be used to generate notebook cells. And normal evaluation of most Input statements will generate a cell, but not from all Input statements. And not if you use ";" to suppress Output cell generation. On the other hand, Show does not generally generate a cell. It just returns a Mathematica expression. In that respect it is not any different than 1+1. One can, however, change the behavior of a plot, or of Show by adding a DisplayFunction option. The following generates no output. Do[Show[Plot[Sin[i x], {x, 0, 3}]], {i, 1, 3}] The following does generate output. Do[Show[Plot[Sin[i x], {x, 0, 3}], DisplayFunction -> (Print[#]; &)], {i, 1, 3}] Of course, it is easier to just apply Print to the Show or Plot statements. So it is possible to make Show generate output cells, but it normally doesn't do so. It normally only generates expressions, which because of its special behavior a Do statement does not display. David Park djmpark at comcast.net http://home.comcast.net/~djmpark/ From: AES [mailto:siegman at stanford.edu] In article <h4951e$q2e$1 at smc.vnet.net>, "David Park" <djmpark at comcast.net> wrote: > A Do loop never generates any output on its own. Print generates the output, > so add a Print header to the Show statement. David, Can't quarrel with your overall response here -- but might you also agree that your two statements above are in a real sense contradictory. To put it another way: * Show, executed in a single cell, sure generates output. * Print, executed in a single cell, sure generates output. So, I think my off-cited even if mythical "ordinary user" would very reasonably conclude that wrapping Show *or* Print in a Do should produce multiple versions of the single-cell output. Producing multiple versions of what some single-cell expression does is what Do loops are *supposed* to "do" -- nicht wahr? And "Show" is as an imperative a verb as is "Print". I'm not really interested in why Print can Do, and Show can't. I'm just noting that this is an easily and reasonably misunderstood situation, and that's unfortunate.