[metapost] variable parameter list

Stephan Hennig mailing_list at arcor.de
Thu Feb 9 11:31:45 CET 2006


Hi,

when calling a macro that has a rather long parameter list I'd like to
make certain parameters optional. That is, I'd like to call a macro with
the _same_ name via

mymacro(a);        %or
mymacro(a, b);     %or
mymacro(a, b, c);

Is there a (recommended) way of doing that with MetaPost?

MetaObj offers a way to do that where optional parameters have to be
given in a key=value syntax which I think is chosen because it is
suitable for being processed via scantokens. But how do I make the text
parameter optional then?

Regards,
Stephan Hennig


vardef mymacro(expr a)(text parb) =
save b; numeric b;
  scantokens(parb); % b is initialized here.
  if (b=0):
    show "One paramer given.";
  else:
    show "Two parameters given.";
  fi
enddef;

beginfig(1);
  mymacro(1)("b=1");
  mymacro(1)("b=0");
endfig;
end



More information about the metapost mailing list