2

Is there a way to convert suffix to string? More specifically, i need to do something like this:

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
    that's what str does. – Thruston Mar 25 '16 at 19:11
3

Try something like this:

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.

Of course, if you want to assign some value of a non-numeric type to something you should declare it appropriately before trying to assign to it. For example, pair something[]; or string something[];

You also might want to think about the scope of the something variables.

  • Thank you! It works just fine. Actually, i tried str (as it was the only operator that looked appropriate to me in mpman), but i wrote it with brackets (str(a)) and it didn't work. – Sergey Slyusarev Mar 25 '16 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.