[metapost] test for empty text?
Daniel H. Luecking
luecking at uark.edu
Tue May 28 15:54:32 CEST 2013
[X]Colin Fraizer [metapost at cfraizer.com] wrote:
> - Is there a way to test if the replacement text of a macro
>is empty?
>I have a macro which expands to a color or to empty (0 tokens),
>in which case I want to use “background”.
I might make use of the fact that a for-loop ignores empty
items in a list. For example:
def getmycolor (text clr) =
for c = clr,background:
mycolor := c;
exitif true;
endfor
...
enddef;
When the parameter clr is empty, one should get
mycolor := background
on the first (only) iteration of the loop, but when clr
is an actual color one should get
mycolor:=clr;
on the first iteration, and then immediately exit the
loop.
I did not test this, but I have done similar things before.
Dan
--
Daniel H. Luecking
Department of Mathematical Sciences
University of Arkansas
Fayetteville, Arkansas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/metapost/attachments/20130528/ba6a9790/attachment.html>
More information about the metapost
mailing list