[metapost] how to get the size of an array

Taco Hoekwater taco at elvenkind.com
Wed Aug 1 17:03:25 CEST 2007


Hello,

Manuel Yguel wrote:
> Hello,
> I have two questions:
> 
> 1) suppose I have an array defined like that
> 
> numeric range[];
> 
> rang[1]:=3; ...
> 
> how can I now the size of this array ?

You can't, unless you maintain a separate counter yourself. Metapost
does not actually have arrays, it has structured variables instead.
The syntax with brackets is a perhaps little misleading; it is shorthand
for "any numeric expression". For instance, you can skip integers, and
use negative, and even fractional values.

> 2) is there equivalent of fopen, fscanf functions in metapost to read
> through a file ?

No, there is nothing like that. Preprocessing the input by using a
scripting language is the usual way of dealing with this issue.

Best wishes,
Taco


More information about the metapost mailing list