metafun: error when I call the same function twice consecutively.
Hi, I defined a function using MetaFun, and call it to draw a figure. It is OK when I call it once. But there is an error when it runs the same function second time. (it stops when it call fap(3,2) after fap(2,2)) I have no idea what is wrong and how to fix it. Would you please tell me what I miss? Thank you. Best regards, Dalyoung %%%%%%% \startbuffer[test] numeric u; u := 1cm; path p[]; def fap(expr n, m) = numeric size; size := m*u; for i = 0 upto (n*n-1): z[i] = ((i mod n),(floor(i/n)))*size; drawdot z[i] withpen pencircle scaled 5pt withcolor blue; endfor; enddef; fap(2,2); fap(3,2); \stopbuffer \starttext \processMPbuffer[test] \stoptext
On 01/06/18 14:22, Jeong Dal wrote:
Hi,
I defined a function using MetaFun, and call it to draw a figure. It is OK when I call it once. But there is an error when it runs the same function second time. (it stops when it call fap(3,2) after fap(2,2))
I have no idea what is wrong and how to fix it. Would you please tell me what I miss?
You have to save x, y; otherwise z[i] = ... will be an ill-defined equation. \startMPpage numeric u; u := 1cm; path p[]; def fap(expr n, m) = begingroup ; save x, y ; numeric size ; size := m*u ; for i = 0 upto (n*n-1): z[i] = ((i mod n),(floor(i/n)))*size; drawdot z[i] withpen pencircle scaled 5pt withcolor blue; endfor ; endgroup ; enddef; fap(2,2); fap(3,2); \stopMPpage
Thank you. Best regards,
Dalyoung
%%%%%%% \startbuffer[test] numeric u; u := 1cm; path p[];
def fap(expr n, m) = numeric size; size := m*u;
for i = 0 upto (n*n-1): z[i] = ((i mod n),(floor(i/n)))*size; drawdot z[i] withpen pencircle scaled 5pt withcolor blue; endfor; enddef;
fap(2,2); fap(3,2); \stopbuffer
\starttext \processMPbuffer[test] \stoptext
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
participants (2)
-
Henri Menke
-
Jeong Dal