Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

RE: newbie Comment question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47028] RE: [mg47018] newbie Comment question
  • From: "David Park" <djmp at earthlink.net>
  • Date: Mon, 22 Mar 2004 05:18:40 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Janos,

Comments in Mathematica are inserted using (* .... *). So you could use...

line1;
(* line2; *)
line3;

However, in my humble opinion, comments in Mathematica are poorly
implemented and, except for commenting out, are almost totally useless. In
package code they cause parsing errors. If you convert an Input Cell from on
Form to another, say from StandardForm to InputForm, the comments are thrown
away.

Weaving some comments into code is a very useful and proper programming
practice. Text cell comments are in no way a substitute for this. Comments
should be considered as part of the proper syntax of all Input cells. They
should not be thrown out when converting between various input Forms. The
parser should handle comments simply by skipping over them.

This is a long standing incorrectly implemented feature of Mathematica.

I would like to point out another, this time good feature of Mathematica
that many are unaware of. It is very convenient to do a calculation with
multiple input lines in one cell. It is also easy to add comments in the
form of Print statement so that you have commented output. You can use the %
and %% expressions quite safely within a single cell. You can use
statement1; and still refer to its output as %. Here is a simple example of
commented output.

Print["Starting equation"]
a x + b == c
Print["Subtract b from both sides"]
# - b & /@ %%
Print["Divide by a"]
#/a & /@ %%

If you close up the Input cell, using Alt-C-R-C, your notebook will have
just the commented output. This is very convenient for displaying
derivations in Mathematica.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

From: János [mailto:janos.lobb at yale.edu]
To: mathgroup at smc.vnet.net

I have lines and lines of codes.  Like

line1;
line2;
line3;

I would like to comment out line2 temporary.  How do I do it ?  I tried
to look hard in the Book last night, but found nothing.

Related question.  If I do not want to insert a text cell to explain
what a line does, how can I add comments to the lines ?

In other languages  /*....*/  or // would work, but not here.  I do not
know yet how to add text cells, but would like to comment the code I
do.

Thanks ahead,

János
-------------------------------------------------
clear perl code is better than unclear awk code; but NOTHING comes
close to unclear perl code
http://www.faqs.org/faqs/computer-lang/awk/faq/



  • Prev by Date: RE: Question on Ordering
  • Next by Date: Re: Manipulating the Front End
  • Previous by thread: Re: newbie Comment question
  • Next by thread: Off[General::spell]