#define MyMacro(x) \ if (x) \ usr << "Foo!" \ else \ usr << "Bar!" \ usr << "Baz!"it fails to compile. Even if I add semicolons after the three expression statements:
#define MyMacro(x) \ if (x) \ usr << "Foo!"; \ else \ usr << "Bar!"; \ usr << "Baz!";it doesn't behave as the indentation suggests it should. The observed behaviour is that the last expression statement is not a part of the else clause of the if statement. In order to achieve the desired behaviour I have to resort to "brace syntax":
#define MyMacro(x) \ if (x) \ { \ usr << "Foo!"; \ } \ else \ { \ usr << "Bar!"; \ usr << "Baz!"; \ }It appears that a \ followed by a newline in a macro definition does not become a real newline in the macro replacement text; a behaviour inherited from the preprocessors of C and C++, but not ideal for a language where newlines and indentation can be part of the syntax.
It would be useful if indent syntax could be used in multi-line macros, but there would have to be a rule for mapping indentation levels in the macro definition to indentation levels in the replacement text inserted. For example, the indentation of the first line after the #define could be mapped to the indentation level of the line where the macro is invoked. Given the macro definition:
#define MyMacro(x) \ if (x) \ usr << "Foo!" \ else \ usr << "Bar!" \ usr << "Baz!"the following code:
/mob verb/TestMyMacro(x) if (isnum(x)) MyMacro(x)would preprocess to:
/mob verb/TestMyMacro(x) if (isnum(x)) if (x) usr << "Foo!" else usr << "Bar!" usr << "Baz!"