Re: Show and 6.0

• To: mathgroup at smc.vnet.net
• Subject: [mg89466] Re: Show and 6.0
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Tue, 10 Jun 2008 03:41:29 -0400 (EDT)

```On 6/9/08 at 2:28 AM, siegman at stanford.edu (AES) wrote:

>I've thought for all my years with Mathematica that you _had_ to put
>semicolons between two successive expressions on the same line or in
>the same cell, except for the very last line in the cell.  And, I
>guess I deduced that this made sense and was necessary because
>logically you always needed to be clear where one expression ended
>and the next one began.

>Given this, I would never have believed that giving as input, on a
>single line and in a single cell, the following

>a = Plot[x, {x, 0, 1}];  b = Plot[x^2, {x, 0, 1}];  a  b

>would be a legal input -- until I tried it a couple of minutes ago.

>But wait a minute!  Aren't a and b now expressions
>(separately)? So, don't they require a semicolon between them,
>to separate them?

If you took one more step (either doing FullForm[%] or Head[%])
after the above, you would see the result is not two plots but
the product of a and b. Since the product of two graphics is an
undefined operation, Mathematica returns the product
unevaluated. But since both a and b evaluate to plots, you see
the two plots with nothing apparent to indicate what you are
really looking at is an unevaluated product.

There really is only one function for the semicolon which is to
separate parts of a compound expression. The fact Mathematica
suppresses output from a compound expression or any expression
terminated by a semicolon is really a side effect. What
Mathematica outputs is the result of the compound expression.
And since

In[5]:= FullForm[expr;]

Out[5]//FullForm= Null

There is no output to display.

The fact Print[expr]; outputs something really isn't an
exception to the rule. Here what happens is the Print statement
executes then Mathematica exectutes the next portion of the
compound expression. A null in this case, which means no further output.

As you have determined, a semicolon isn't necessary between
expressions to get meaningful output. But it is good practice to
use a semicolon. Usage of the semicolon prevents Mathematica
from interpreting spaces or returns between parts of the
expression as an implied multiply

a = Plot[x, {x, 0, 1}]; b = Plot[x^2, {x, 0, 1}];
a
b

Results in two plots rather than a multiply operation which is
probably what would be intended. Although this does work, I
would code it as

a = Plot[x, {x, 0, 1}]; b = Plot[x^2, {x, 0, 1}];
GraphicsColumn[{a, b}]

since I have found occasionally the return gets interpreted as a
multiply by Mathematica, possibly due to corruption of the
notebook in some manner. By using GraphicsColumn instead of a
return to separate a and b there is nothing left to interpretation.

```

• Prev by Date: Re: Re: Selecting Element from List via Pattern
• Next by Date: Re: Re: Re: Adding markers on the surface of a Plot3D?
• Previous by thread: Re: Show and 6.0
• Next by thread: Re: Show and 6.0