字串的 Metapost 後綴

字串的 Metapost 後綴

有沒有辦法轉換後綴細繩?更具體地說,我需要做這樣的事情:

def myMacro (suffix a, b) =
    something.a = fOne(a);
    something.b = fOne(b);
    something.scantokens("somethingelse"&**suffixtostring**(a)&**suffixtostring**(b)) = fTwo(a,b);
enddef;

答案1

試試這樣的事情:

def your_macro(suffix a, b) = 
  something.a = 42;
  something.b = 64;
  something.scantokens("prefix" & str a & str b & "suffix") = 94;
enddef;

your_macro(p,q);

show something.prefixpqsuffix;
% shows 94

end.

如果要指派非數字類型的某些值,則應something在嘗試指派之前適當聲明它。例如,pair something[];string something[];。但請注意,如果您這樣做,後綴必須有效數位值,因為用 宣告的集體下標[]只能是數字。

您可能還需要考慮something變數的範圍。

相關內容