[metapost] How to ignore a comma?

Mojca Miklavec mojca.miklavec.lists at gmail.com
Sun Feb 4 20:57:47 CET 2007


Hello,

This might be easy to do, but I don't know how. I would like to write
a few simple macros accepting an arbitrary number of arguments.
Arguments are usually passed to metapost with a comma inbetween, but
if one sends "text" arguments, comma of course doesn't work. I could
put semicolon or a space between, but it looks a bit unnatural.

How can I ask metapost for ignoring the next character if it happens
to be a comma? See the example below:

beginfig(1);

def do_something(expr xx, yy)(text t) =

	% default values
	save c; color c; c = black;
	save d; numeric d; d = 5pt;

	def set_color(expr col) =
		c := col;
	enddef;

	def set_size(expr size) =
		d := size;
	enddef;

	t;

	fill fullcircle scaled d shifted (xx,yy) withcolor c;
enddef;

% simple examples
do_something(1cm,2cm,set_color(blue));
do_something(2cm,1cm,set_size(10pt));

% this works OK
do_something(2.5cm,1.5cm,set_color(red) set_size(8pt));

% this works OK
do_something(2cm,2.5cm,set_color(green);set_size(8pt));

% but the following syntax would look better
% do_something(2.5cm,1.5cm,set_color(red),set_size(8pt));

draw unitsquare scaled 3cm;

endfig;
end.


I would be very grateful for any hints about how to make the last
example work. (I believe that it should be possible to do so.)

Thanks a lot,
    Mojca


More information about the metapost mailing list