[metapost] [graph.mp] bug in gdata?

Stephan Hennig mailing_list at arcor.de
Sat Mar 3 21:46:40 CET 2007


[Full quote, because this mail wasn't copied to the list.]

Ryan Van Wagoner schrieb:
> Hi Stephen,
> 
> in graph.mp, gdata is implemented as:
> 
> def gdata(expr f)(suffix $)(text c) =
>   for i=1 upto infinity:
>     exitunless Grdln_$(f);
>     c
>   endfor
> enddef;
> 
> It appears that `i' is a loop variable in the context that your text
> parameter is evaluated in, and therefore should not be assigned to.

Why use i at all here?  What about

forever: exitunless ... ?


> Does anyone know if there is a way to create unique or non-referencable
> parameters to prevent these collisions from happening (similar to
> `gensym' in common lisp or the concept of hygenic macros in Scheme)?
> Maybe the loop variable in gdata should be called `i_' as seems to be
> the convention that Knuth suggests in "The Metafont Book" for variables
> internal to a format or input program.

Would be a much better idea if forever can't be used there, since i is
such a common index name.  It took me ages to find this out, because I
knew I did something similar already.  With another substitute name
obviously.

Best regards,
Stephan Hennig


> 
> Regards,
> 
> Ryan
> 
>>>>>> "Stephen Hennig" == Stephan Hennig <mailing_list at arcor.de> writes:
> 
>  Stephen Hennig> Hi,
>  Stephen Hennig> in the following file manipulating a variable j or (any?) other variable
>  Stephen Hennig> inside gdata (from graph.mp) works fine.  Except for variable i.  That
>  Stephen Hennig> variable throws and error in MetaPost v0.901.  A bug?
> 
>  Stephen Hennig> Best regards,
>  Stephen Hennig> Stephan Hennig
> 
>  Stephen Hennig> input graph
>  Stephen Hennig> beginfig(1);
>  Stephen Hennig> numeric i, j;
>  Stephen Hennig>   j := 0;
>  Stephen Hennig>   gdata("test.dat", v, j:=j+1; );%%% Works.
>  Stephen Hennig> %   i := 0;
>  Stephen Hennig> %   gdata("test.dat", v, i:=i+1; );%%% Fails.
>  Stephen Hennig> endfig;
>  Stephen Hennig> end
> 
>  Stephen Hennig> Instead of "test.dat" you can take any file name of a text file, e.g.,
>  Stephen Hennig> the MetaPost source file name itself.
> 
>  Stephen Hennig> _______________________________________________
>  Stephen Hennig> metapost mailing list
>  Stephen Hennig> http://tug.org/mailman/listinfo/metapost
> 



More information about the metapost mailing list