EUROPEAN ORGANIZATION FOR NUCLEAR RESEARCH

Program Flow Statements

label: macro = {statement 1; statement 2; ...; statement n; };
label(arg1,...,argn): macro = {statement 1; statement 2; ...; statement n; };
The first form allows the execution of a group of statements via a single command:
exec, label;
will execute the statements in curly brackets exactly once. This command can be issued any number of times.

The second form allows to replace strings anywhere inside the statements in curly brackets by other strings, or integer numbers prior to execution. This is a powerful construct and should be handled with care.

Simple example:

option,-echo,-info;  ! otherwise the output is somewhat confusing
simple(xx,yy): macro = { xx = yy^2 + xx; value, xx;};
a = 3;
b = 5;
exec, simple(a,b);

Somewhat more tricky (a "$" in front of an argument means that the truncated integer value of this argument is used for replacement, rather than the argument string itself).

tricky(xx,yy,zz): macro = {mzz.yy: xx, l = 1.yy, kzz = k.yy;};
n=0;
while (n < 3)
{
  n = n+1;
  exec,tricky(quadrupole,$n,1);
  exec,tricky(sextupole,$n,2);
};
Whereas the actual use of the preceding example is NOT recommended, a real life example, showing the full power (!) of macros is to be found under macro usage for the usage, and under macro definition for the definition.

Beware of the following rules:

  • Generally speaking: special constructs like IF, WHILE, MACRO will only allow one level of inclusion of another special construct .
  • Macros must not be called with numbers, but with strings (i.e. variable names in case of numerical values), i.e.

    NOT

    exec,thismacro($99,$129);
    
    BUT
    n1=99; n2=219;
    exec,thismacro($n1,$n2);
    
    hansg, June 17, 2002