macro01.gms : several macro tests


Contributor: Alex

  1 %xx% are replaced before we recognize a comment or $control

Small Model of Type : GAMS

Category : GAMS Test library

Main file : macro01.gms

$title several macro tests (MACRO01,SEQ=403)

Contributor: Alex

* 1 %xx% are replaced before we recognize a comment or $control
$set star * this is a comment
$set dco $show

* 2 macro expansion does not reset the system to recognize comments and $control
$macro star * this is a comment
$macro dco  $show
$if errorfree $abort we should have an error

* 3 macro names do not clash with environment varaiables
$set   setid this is in a different names space
$macro setid display 'something different'
display '%setid%';

* 4 no macro expansion on $ controls
$macro remark garbage
$remark this is a comment
$if not errorfree $abort wrong macro substitution

* 5 no subtitutions on $macro
$macro oldname newname
$macro oldname display 'this should not be dco';
$if errorfree $abort wrong macro substitution on macro

* 6 offtext remains untouched
$macro offtext this is weird
$macro ontext  this is weird too

$onecho >

* 7 check if defined decalred and of right type
$if NOT defined  setid $abort missed macro definition test
$if NOT declared setid $abort missed macro declaration test
$if NOT mactype  setid $abort missed macro type test

* 8 declaration list test
$macro macroname newname2
set oldname
$if errorfree $abort should not have done substitution

* 9 macro substitution should be done in domain list
$macro im i
$macro jm j
$macro ijm im,jm
$macro ijma(k) k,k
set i, j;
set ijset(im,jm,ijm,ijma(i),ijma(jm));
$if not errorfree $abort wrong macro substitution

* 10 .local is recognized
set q /1*3/,i /2*4/; alias (q,w); parameter b(*) / 1 2, 3 8 /, c(*);
$macro qq(i) sum(i.local, b(i))
c(q) = qq(q); abort$sum(q, c(q) - sum(w, b(w))) c;

* 11 default is not to expand aruments
variable x(*,*);
$macro  f(i)   sum(q, x(i,q))
$macro equ(x)  equation equ_&x; equ_&x.. &x =e= 0;
* equation equ_f(I); equ_f(i).. f(i) =e= 0;

* 12 $onexpand will process/expand the macro arguments
* equation equ_sum(q, x(i,q)); equ_sum(q, x(i,q)).. sum(q, x(i,q)) =e= 0;
$if errorfree $abort this should give errors