MathGroup Archive 2010

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

Search the Archive

Re: Show left hand side

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111042] Re: Show left hand side
  • From: Helen Read <hpr at together.net>
  • Date: Sun, 18 Jul 2010 01:03:42 -0400 (EDT)
  • References: <i1s6vd$a2u$1@smc.vnet.net>
  • Reply-to: HPR <read at math.uvm.edu>

On 7/17/2010 8:16 AM, Sam Takoy wrote:
> Hi,
>
> When Mathematica prints an expression not terminated by a semicolon, I
> find it hard to match up the output with what I was trying output when a
> block of commands has many commands not terminated by a semicolon.

I don't think it is a good idea to have a block of commands all in one 
cell that are not separated by semi-colons. As you point out, it is 
difficult to follow. Worse, it can easily lead to errors. For example 
two things that you intended as separate commands end up getting 
multiplied together. If you need to see the output of each command, put 
each input in a separate cell. Then you will have a sequence 
input/output, input/output, which is very easy to read and follow. If 
you find it tiresome to evaluate each input one by one, put them all in 
a section and select the cell bracket for the entire section. Then when 
you evaluate (Shift-Enter), everything that is selected will be evaluated.

On the other hand, if you only to see output from the last command, put 
it all in a single cell, separating the commands with semi-colons (and 
no semi-colon on the last one).

For a block of code that you will re-use with different input, write a 
function in the form of a Module or Block. Use Print within the Module 
(or Block) anywhere you want to see output.

> Is there a way to get Mathematica to output the LHS so when I have
> R=1+1 it outputs R = 2 or something like that.

Print a Row. This is especially useful within a Module or Block.

r = 1 + 1;
Print[Row[{"r = ", r}]];

One last comment: it is a good habit to use lower case letters for your 
own variable and function names, to avoid inadvertent conflicts with 
built-in functions and symbols. I also think it makes it a bit easier to 
read your code that way -- it is immediately clear which functions and 
symbols you have defined yourself, and which ones are built-in.

If you have very long function names, you can use what is sometimes 
called camel case.

myVeryLongFunctionNameInCamelCase[x_,y_,z_]:= x^2+2y+z


-- 
Helen Read


  • Prev by Date: Re: total newbie
  • Next by Date: Re: How to parametrize a block of commands?
  • Previous by thread: Re: Show left hand side
  • Next by thread: Re: Show left hand side