[metapost] variable parameter list

Dan Luecking luecking at uark.edu
Thu Feb 9 17:34:20 CET 2006


At 04:31 AM 2/9/2006, you wrote:
>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?

Not that I know of. I would like to see examples or any suggestions
as I would like to do something like this too.


>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?

vardef mymacro (expr a) text T =
save b; b:=0;
for t=T: scantokens t; b:= b+1; endfor
if b=0;
   show "no argumants"
...
fi
enddef;
...
mymacro (a);
mymacro (a) "b = 0";
mymacro (a) "b=1", "b=2";

Of course you have to be able to deal with empty text. It turns
out a for loop doesn't care if a list of expresions is empty.

I would like to be able to have a key-value syntax without the
quotation marks, but I don't see any way to do that.


Dan


Daniel H. Luecking
Department of Mathematical Sciences
University of Arkansas
"Be kind. Every person you meet is fighting a hard battle." - Anon.



More information about the metapost mailing list