Neither this nor this formally states that comments never affect the program execution, but I believe that this is a reasonable expectation.
At this time I am puzzled with the following situation (minimal example):
Execution:
There is no difference between the line 1 and line 5 (the first and the third local declaration) except for the presence of a comment in the latter.
The reason (as the second declaration demonstrates) seems to be premature reaction to the closing compound quote ("+') since adding a space between the quote and apostrophe reestablishes program validity. But this doesn't explain why the program then works when there is no comment in the line (first declaration) and leaves me wondering whether this will always be the same case.
IMHO while evaluating an expression Stata should look left to right and put to the stack the 'expectations' - for an opening quote I must expect a closing quote, for opening apostrophe its matching cousin, etc. with expectations being removed from the stack when actually encountered or error reported when closing 'thin' does not match an expectation. With that all three declarations would have been valid. My interpretation may, of course be wrong, and there may be the cases where programmers may prefer opposite behavior (where the quotes are superior in priority to evaluation apostrophes), but in any case the comment shouldn't change the behavior.
(my real case is much more complex of course with several levels of quotes and string function calls, but it still boils down to this minimal example).
(Stata 13 for Windows if this matters).
Interestingly, the syntax highlighter correctly highlights the second declaration with a maroon color indicating a string content, while not highlighting it that way in the third declaration, possibly indicating, "hey, there is something wrong here", but then again, in the first declaration there is also no highlighting, yet it works fine.
Thank you, Sergiy Radyakin
PS: I also can't explain why the following
1) produces output 2) produces that specific output; and 3) is not considered a mistake, but that is of lesser importance...
At this time I am puzzled with the following situation (minimal example):
Code:
local test `"`="aaa"+"bbb"'"' display `"[`test']"' local test `"`="aaa"+"bbb" '"' // this does work display `"[`test']"' local test `"`="aaa"+"bbb"'"' // this doesn't work display `"[`test']"'
Code:
. local test `"`="aaa"+"bbb"'"'
. display `"[`test']"'
[aaabbb]
. local test `"`="aaa"+"bbb" '"' // this does work
. display `"[`test']"'
[aaabbb]
. local test `"`="aaa"+"bbb"'"' // this doesn't work
invalid syntax
r(198);
The reason (as the second declaration demonstrates) seems to be premature reaction to the closing compound quote ("+') since adding a space between the quote and apostrophe reestablishes program validity. But this doesn't explain why the program then works when there is no comment in the line (first declaration) and leaves me wondering whether this will always be the same case.
IMHO while evaluating an expression Stata should look left to right and put to the stack the 'expectations' - for an opening quote I must expect a closing quote, for opening apostrophe its matching cousin, etc. with expectations being removed from the stack when actually encountered or error reported when closing 'thin' does not match an expectation. With that all three declarations would have been valid. My interpretation may, of course be wrong, and there may be the cases where programmers may prefer opposite behavior (where the quotes are superior in priority to evaluation apostrophes), but in any case the comment shouldn't change the behavior.
(my real case is much more complex of course with several levels of quotes and string function calls, but it still boils down to this minimal example).
(Stata 13 for Windows if this matters).
Interestingly, the syntax highlighter correctly highlights the second declaration with a maroon color indicating a string content, while not highlighting it that way in the third declaration, possibly indicating, "hey, there is something wrong here", but then again, in the first declaration there is also no highlighting, yet it works fine.
Thank you, Sergiy Radyakin
PS: I also can't explain why the following
Code:
. di `""'"' '
Comment