Conditional compilation (was: Erlang/OTP R10B-10 has been released)

Richard A. O'Keefe <>
Thu Mar 30 06:22:21 CEST 2006


"Vlad Dumitrescu XX \(LN/EAB\)" <>
asked:
	Is it really that bad?

I received another copy earlier as private mail, so answered it privately.

Briefly, the answer is "yes it IS that bad".

Basically,
 - comments that are designed to wrap around code cannot handle free text.
   (Back in the days of UNIX Version 7 on a PDP-11, I used to use
	#if 0
	lots of comment stuff here
	#endif 0
    as "big block comments".  However, under the rules of ANSI C89 that
    just does not work:  the stuff inside #if/#endif *must* be made up of
    well formed preprocessing-tokens.)

 - comments that are designed to handle free text (constrained perhaps so
   that comment brackets balance) cannot handle code.

In short, you need TWO kinds of comments.

    token -> constant | identifier | keyword | punctuation | space
    space -> white space character | end of line comment |
             text comment |
             code comment

    text comment -> "(*" ("not (*" | "not *)" | ok char | text comment)* "*)"

    code comment -> "[*" token* "*]"

You can comment code out by wrapping code comment brackets around it,
but you had better be darned sure NOT to use text comment brackets.

You can include free text by wrapping text comment brackets around it,
but you had better be darned sure NOT to use code comment brackets.

Because text and code follow DIFFERENT lexical rules.

If there is a language that has two kinds of comment like that, then
yes, nesting comments work in it.  (PROVIDED you always use the right kind!)

All the languages I know that claim to have nesting comments
try to use text comments for both jobs, and that's what doesn't Work.
(Because text comments do not know about string and atom tokens.)




More information about the erlang-questions mailing list