1

I would like to fill paths of arrays of arbitral length using a loop. Is there a way to iterate the fill operator on each array element, something equivalent to this shell loop

set -A Test foo bar
for i in ${Foo[@]}; do print $i; done

AFAIU METAPOST arrays are not classical arrays, so I don't know if this can be achieved. What I'm doing so far looks like this MWE. Works so far, since my path arrays did not grow to more than ten elements, but if it did, I may overlook that something hasn't been filled. Checking the arrays lengths is what I'd like to avoid.

\mainlanguage[]
\language[]

\starttext \startMPpage path T[];

T1:=unitcircle scaled 20; T2:=unitsquare scaled 20 xshifted 30; T3:=unitcircle scaled 20 xshifted 80;

for i=1 step 1 until 10: if known T[i]: draw T[i] ; fi endfor ; \stopMPpage \stoptext

sztruks
  • 3,074

1 Answers1

1

You could try forever:

\starttext
\startMPpage
path T[];

T1:=unitcircle scaled 20; T2:=unitsquare scaled 20 xshifted 30; T3:=unitcircle scaled 20 xshifted 80;

i:=1; forever: if known T[i]: draw T[i]; i:=i+1; fi exitif unknown T[i]; endfor ; \stopMPpage \stoptext

mickep
  • 8,685
  • Thanks! Nice idea. I’ll accept the answer if it turns out there is no "i-independant" way way to have all the array elements listed. – sztruks Aug 30 '20 at 15:20