MathGroup Archive 1999

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

Search the Archive

Red comments can yield corrupt Notebooks in 4.0

  • To: mathgroup at smc.vnet.net
  • Subject: [mg18397] Red comments can yield corrupt Notebooks in 4.0
  • From: jsobel at sdav01.seinf.abb.se (Jarl R Sobel)
  • Date: Wed, 7 Jul 1999 00:11:00 -0400
  • Organization: ABB Automation Products
  • Sender: owner-wri-mathgroup at wolfram.com

It is good programming practice to comment your code. Many text editors
automatically color the comments in e.g. red, in order to improve the
readability of programs. In Mathematica 3 and 4 you can do this manually 
by
selecting a comment end choosing a text color on the Format menu.

Doing so in Mathematica 4.0 can prevent parts of your code from being
executed. Also, if you have a version 3.0 notebook with comments in color
,
it may be that version 4.0 cannot read it properly.

The notebooks look alright, so it can be rather confusing.

For example, consider the following simple Module.

test1 :=
  Module[
    {},
    (* Here is a comment *)
    Print["This isn't executed with red comments."];
    Print["Neither is this !"
    ];
    Print["This is executed !"]
  ]

Copy the cell to another location, rename the Module to test2 and color the
comment red. Highlight it, and choose Text Color Red on the Format menu.

Then, save the notebook and reopen it.

If you look carefully, you can see that something has happened with the
notebook. The closing parenthesis of the second Print statement of test2 
is no longer aligned under the letter "P" of Print. The automatic indentation
is one nice new feature in 4.0 that is of great help in programming.

Execute the two functions. This it what happens on a Macintosh 9600/350
under Mac OS 8.6 running Mathematica 4.0.0.

In[1]:=
   test1 :=
     Module[
      {},
      (* Here is a comment *)
      Print["This isn't executed with red comments."];
      Print["Neither is this !"
      ];
      Print["This is executed !"]
     ]

In[2]:=
   test2 :=
    Module[
     {},
     (* Here is a red comment *) 
     Print["This isn't executed with red comments."];
     Print["Neither is this !"
      ];
     Print["This is executed !"]
    ]

In[3]:=
   test1

   "This isn't executed with red comments."

   "Neither is this !"

   "This is executed !"

In[4]:=
   test2

   "This is executed !"

As you can see, the first two Print statements of test2 are not executed.
You can see why, if you inspect the definition of test2 in the Kernel.

In[5]:=
   ?? test2

   "Global`test2"

   test2 := Module[{}, Print[This is executed !]]

You can also try the command Convert To Standard Form on the Edit Menu.
This causes the first Print statements to disappear. Apparently, the
colored comment prevents the Front End from sending the first statements
following the comment to the Kernel.

Colored comments don't always cause this behavior. I think it may have to
do with comments that follow a comma in the code. For example:

test3 :=
   Module[
    {},
    Print[""];
    (* Here is a red comment *)
    Print["This is still executed with red comments."
    ];
    Print["This is executed !"]
   ]

can have a  colored comment and yet be saved, reopened, and executed
without problems.

According to Wolfram Research, the problem is not related to the comment 
in
itself, but to the presence of an "empty" StyleBox.
Jarl R Sobel


  • Prev by Date: response regarding rotated text in PostScript graphics
  • Next by Date: Re: HOW BEST: Mathematica figs -> Textures on Mac -> PDF
  • Previous by thread: response regarding rotated text in PostScript graphics
  • Next by thread: Re: HOW BEST: Mathematica figs -> Textures on Mac -> PDF