[metapost] How to ignore a comma?

Mojca Miklavec mojca.miklavec.lists at gmail.com
Wed Feb 7 19:55:19 CET 2007


Hello,

I have now managed to implement all the macros exactly in the way I
wanted apart from a few tiny details. I have two problems left:

1. The following syntax

def do_something(expr p)(text t) =
   ...
enddef;

doesn't allow using
    do_something(3);
but one has to use at least
    do_something(3,);

Is there a solution for it (p will be a path in my case)?

2. A much more serious problem:

I would like to use definitions with multiple parameters:
    do_something(set_angle(30),set_color(.3,.4,.7))

If set_angle redefines the comma into semicolon, I suspect that the
problem arises for
   set_angle(30);set_color(.3;

Is there a way to "let" the let redefine only the first comma it sees?
In "TeX pseudo-code" that would be:

   \let\normalcomma\comma
   \def\comma{\semicolon \let\comma\normalcomma}

Thanks a lot,
    Mojca

(I know that there are workarounds and other possible ways to specify
arguments, but I would really like to have a clean interface and I'm
sure that that should be possible in metapost.)

> def do_something(expr xx, yy)(text t) =
>         save c; color c; c = black;
>         save d; numeric d; d = 5pt;
>
>         let@=,;
>
>         def set_color(expr col) =
>                 let,=@;
>                 let@=,;
>                 c := col;
>                 let,=;;
>         enddef;
>
>         def set_size(expr size) =
>                 let,=@;
>                 let@=,;
>                 d := size;
>                 let,=;;
>         enddef;
>
>         t;
>         let,=@;
>
>         fill fullcircle scaled d shifted (xx,yy) withcolor c;
> enddef;
>
> do_something(2.5cm,1.5cm,set_color(blue),set_size(8pt));
>
> draw unitsquare scaled 3cm;


More information about the metapost mailing list