User Tools

Site Tools


gams:problems_with_spaces_in_nested_macros

Problems with spaces in nested macros

Q: Consider the following program:

 
$MACRO MA parameter a;
$MACRO MXY parameter x;  \
   MA                    \
   parameter y;
 
MXY
 

This does not work because the macro MXY contains:

 
   parameter x;MAparameter y;

and the name MAparameter is unknown.

Answer: Try:

$MACRO MA parameter a;
$MACRO MXY parameter x;  &\
   MA &                   \
   parameter y;

MXY

When storing a macro, leading and trailing blanks are removed from each line. The recognition of macros and expansion of arguments can further be controlled by the use of ampersands (&) in the macro body. A single ampersand (&) is used as a concatenation or separation symbol to recognize tokens to be replaced. Two ampersands (&&) immediately preceding a token will drop the most outer matching single or double quotes of the replacement argument.

gams/problems_with_spaces_in_nested_macros.txt · Last modified: 2010/05/20 15:07 by support