[metapost] How to ignore a comma?

L. Nobre G. nobre at cii.fc.ul.pt
Sun Feb 4 23:22:11 CET 2007


Hint: forget about an arbitrary number of "text" arguments (I know
that forgetting is not so easy).

def somefunc( expr eone, etwo )( text tone )( text ttwo ) =
      [...]
enddef;

beginfig(1);
    pair vectors[];
    path a;
    pen b;
    [...]
    vectors0 = (23,34);
    somefunc( a, b )( dashed evenly )( vectors );
endfig;

On 04/02/07, Mojca Miklavec <mojca.miklavec.lists at gmail.com> wrote:
> 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
> _______________________________________________
> metapost mailing list
> http://tug.org/mailman/listinfo/metapost
>


-- 
L. Nobre G. - http://lnobreg.googlepages.com/
--
"In the end, self-limitation is the only answer that counts, but that
is the answer that no one wants to hear. So we sit, and wait, and
assume, and deny." Richard Heinberg in Powerdown


More information about the metapost mailing list