Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: mulitple comments using // and #d;

From   "Michael S. Hanson" <[email protected]>
To   [email protected]
Subject   Re: st: RE: mulitple comments using // and #d;
Date   Fri, 1 Sep 2006 16:48:31 -0400

On Sep 1, 2006, at 3:52 PM, Nick Cox wrote:

s Stata expected to act on both semi-colons or
just the end one? A rule that some characters
are _forbidden_ within comments would be most
unStataish. Comments should be your own space.

If that's the diagnosis, then // is incompatible
with #delimit ;

-- and that's not a bug or a misfeature or even a limitation. It's just a fact of life.

Someone may have a better story.
I don't necessarily have a better story, but some additional observations and suggestions.

First, I agree with Nick that using -delimit- is not the best way to program in Stata (any more). At best, I would suggest, it is a relic of times gone by, and should be depreciated in favor of ///. But that also may give one a clue towards what might be a "better" story.

Consistent with some other program languages (which I mercifully have long stopped using), Stata also allows a comment to be denoted by an asterisk -- *if* it is the first character on a line. Thus, while

#delimit ;
// comment
// comment;

will not work,

#delimit ;
* comment
* comment;

*does* work, provided the trailing semicolon in the final comment is included. I suspect that * comments are parsed differently than // comments -- which, incidentally, can appear anywhere in a line -- and that is why the second example works. While I completely lack any supporting evidence, I suspect this too, is a relic of times gone by.

Alternatively, if you *start* a // comment line with a semicolon, as

#delimit ;
;// comment
;// comment

the code works as well, but IMHO that is *really* ugly. Again, I suspect your best bet is to scrap the use of -delimit- and adopt // for comments and /// for line continuations. With a decent text editor, you can have these character strings highlighted as a unique part of the syntax, which makes editing your code that much easier. (I also think it would be helpful if Stata's build-in editor provided some degree of basic syntax highlighting, as in this example, but I recognize that is a controversial view around here... to say the least.)

-- Mike

* For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index