[metapost] Recent bug report

Boguslaw Jackowski B_Jackowski at GUST.org.pl
Mon Sep 1 12:17:02 CEST 2008


Hi,

Dan Luecking:
> I did not report that grid.mp fails; I reported that the
> "bug occurs". Naturally I used a test file trimmed down to
> only one relevant command:
> % test.mp
> beginfig(0);
>    drawarrow (0,0)--(50,50)
>      if 2=2: withcolor red elseif 3=2: withcolor blue fi;
> endfig;
> end
> % end of test.mp
> 
> All 4 versions mentioned above (on windows XP, if that matters)
> produced the error message: "! Extra elseif".

I could not believe that it is an MP bug... Just in case I tested
the archaic version 0.641 -- with the same result. Ufff... ;-)

The problem is in the definition of drawarrow (thanks to Piotr
Strzelczyk for the suggestion):

   path _apth;
   def drawarrow expr p = _apth:=p; _finarr enddef;

   def _finarr text t =
     draw _apth t;
     filldraw arrowhead _apth  t
   enddef;

Namely, `drawarrow' swallows the longest text that could/might represent 
an expression. In our case, it is `(0,0)--(50,50) if 2=2:'; the keyword
`withcolor' ends the paths expression. Therefore, the text parameter of
`_finarr' reads `withcolor red elseif 3=2: withcolor blue fi' which for
obvious reason is bound to cause issuing the error message
"! Extra elseif".

Note that the following alteration works:

% test.mp
beginfig(0);
    drawarrow (0,0)--(50,50) withcolor if 2=2: red elseif 3=2: blue fi;
endfig;
end
% end of test.mp

I cannot see another method for finishing explicitly the path expression 
in this case.

Cheers -- Jacko

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  Bogus\l{}aw Jackowski: B_Jackowski at GUST.ORG.PL
----------------------------------------------------------------
  Hofstadter's Law: It always takes longer than you expect, even
                    when you take into account Hofstadter's Law.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-




More information about the metapost mailing list