填入 METAPOST 陣列的所有元素

填入 METAPOST 陣列的所有元素

我想使用循環填充任意長度的數組的路徑。有沒有辦法在每個數組元素上迭代填充運算符,相當於這個 shell 循環

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

AFAIU METAPOST 陣列不是經典數組,所以我不知道是否可以實現。到目前為止我所做的看起來就像這個 MWE。到目前為止,由於我的路徑數組沒有增長到超過十個元素,所以有效,但如果增長了,我可能會忽略某些內容尚未填充。檢查數組長度是我想避免的。

\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

答案1

你可以嘗試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

相關內容