# The array name rule in metapost

Suppose I have defined an array of points

``````pair p[];
``````

Then are `p.0`, `p0`, `p[0]` different? Can I use `p.01`, `p01`, `p[01]`?

According to the rules, `p.0` is the variable `p` subscripted by the number `.0` (which is equal to `0`). Thus `p.0`, `p0` and `p[0]` are the same variable.

Here's an interactive version:

``````This is MetaPost, version 1.803 (kpathsea version 6.1.1)
**\relax
(mpost.mp (/usr/local/texlive/2013/texmf-dist/metapost/base/plain.mp
*pair p[];
*p0=(2,3); show p0; show p[0]; show p.0;
>> (2,3)
>> (2,3)
>> (2,3)
*p1=(1,2); show p[1]; show p[01]; show p.1;
>> (xpart p0.1,ypart p0.1)
>> (1,2)
>> (1,2)
``````

Note that `p1` and `p.1` are not the same. The number 1 can be equivalently typed `1` and `01`, so `p1`, `p01`, `p[1]` and `p[01]` are exactly the same. However, `p. 1` (with a space) is the same as `p1`.

Metapost splits its input into tokens. You find the definition of token in section 7.1 of the manual (`texdoc metapost`). The rules say that

``````p.1
``````

is formed by two tokens, a symbolic one `p` and a numeric token `.1`; while symbolic tokens can assume different meanings, numeric tokens always mean the corresponding number, in this case 0.1, because it's legal to type it as `0.1`, `.1`, `0.10` or any other way compatible with the rules.

A different case is `p. 1`; a space always makes Metapost end its look up for a token name. Also `.` does the same, provided it's not immediately followed by a digit or another period. When a space or period has done its stopping job, it's ignored. So

p 1 p. 1 p1 p[1]

are completely equivalent methods for referring to the same variable. Not `p.1`, I repeat, which is equivalent to `p0.1` or `p[0.1]`. The “bracket rule” is in another place, where arrays are dealt with.

• Then, what's the exact meaning of `p.1`? why it is equal to `p0.1`? and how to understand it? Thanks Jan 22, 2014 at 9:06
• @user19832: As egreg explained, .1 is the same as 0.1 for MetaPost. Any period, if it is immediately followed by one digit or more, is considered as the period of a "numeric token" (a number) and thus part of a number. Jan 24, 2014 at 11:21