Re: Mathematica commenting of code using (* *) can't be nested
- To: mathgroup at smc.vnet.net
- Subject: [mg84937] Re: Mathematica commenting of code using (* *) can't be nested
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Sun, 20 Jan 2008 03:37:26 -0500 (EST)
- References: <fmsljm$knj$1@smc.vnet.net>
Nasser Abbasi wrote: > Mathematica 6.0.1 > > I do not understand why the following can't be taken as a valid comment > > (* comment here (* more comments *) > > It seems to me that once the first (* is seen by the parser then it should > take everything in front of it, all the way until it sees the closing *) as > one comment. > > But in the above it does not. The (* in the middle breaks this, which does > not make too much sense to me. What do you think? I think that it makes a lot of sense, because Mathematica has only one syntax for commenting. Compare it with the C language where if there are any comments inserted into a function, like this, void fun() { statement1; statement2; /* comment */ statement3; } , then the whole function cannot be commented out: /* void fun() { statement1; statement2; /* comment */ <-- comment is broken here statement3; } */ The usual C solution is to use the preprocessor to work around this problem: #if 0 void fun() { statement1; statement2; /* comment */ statement3; } #endif Fortunately Mathematica (at least the latest version of it) allows the nesting of comments, so this is not a problem. I am not sure whether comment nesting has worked correctly in older versions. I saw a note about this in the Mathematica syntax highlighting file included with a certain text editor that says that "the frontend won't always like [nested comments]". -- Szabolcs