[metapost] variable parameter list

Daniel H. Luecking luecking at uark.edu
Mon Feb 13 18:19:33 CET 2006


On Fri, 10 Feb 2006, Stephan Hennig wrote:

> Dan Luecking schrieb:
> > At 04:31 AM 2/9/2006, you wrote:
> >
> >>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 =
>
>
> Thanks Dan, this seem to work (now even better with Jens-Uwe's
> solution). But could you please point me to the page in the MetaPost
> manual where this syntax is explained or could you please explain why
> this works?

In the MetaPost manual (version 0.9), section 9.5, page 53:
"Undelimited text parameters run to the end of a statement. More
precisely, an undelimited text parameter is the list of tokens following
the macro call up to the first ; or endgroup or end except that an
argument containing begingroup will always include the matching
endgroup."

I confess I learned it from the Metafontbook, which contains almost
the same description:

"An undelimited text essentially runs to the end of the current
statement; more precisely, it runs to the first ';' or 'endgroup' or
'end' that is not part of a group within the argument."

This seems to be somewhat circular as it is not clear what the
"argument" is for the group to be "within" until the rule is applied.
However, experimentation shows that an undelimited text argument must
contain balanced begingroup-endgroup pairs (but needn't have balance
parentheses).

> How does the text following the macro call get into
> "parameter" T. I didn't find a discussion of unparenthesized parameters
> in macro definitions in section 9.2.

As above: everything to the end of the statement containing mymacro is
read into T without expansion. Assuming it is a comma-separated list of
expressions, it can be used in "for s = T:". I discovered accidentally
(in the course of developing parts of mfpic) that an empty T simply
causes the for-loop to be skipped.


-- 
Dan Luecking
Dept. of Mathematical Sciences
University of Arkansas
Fayetteville, AR 72101



More information about the metapost mailing list