ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Henri Menke <henrimenke@gmail.com>
To: ntg-context@ntg.nl
Subject: Re: metafun: error when I call the same function twice consecutively.
Date: Fri, 1 Jun 2018 15:19:38 +1200	[thread overview]
Message-ID: <8175246b-1260-1501-a37d-9e5ef8dbf29c@gmail.com> (raw)
In-Reply-To: <BC9190C3-A664-4828-A55F-88528C64150F@me.com>



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
> ___________________________________________________________________________________
> 
___________________________________________________________________________________
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
___________________________________________________________________________________

  reply	other threads:[~2018-06-01  3:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1.1527760801.30763.ntg-context@ntg.nl>
2018-06-01  2:22 ` Jeong Dal
2018-06-01  3:19   ` Henri Menke [this message]
     [not found] <mailman.1.1527847201.14764.ntg-context@ntg.nl>
2018-06-01 11:29 ` Jeong Dal
2018-06-01 14:24   ` Alan Braslau
2018-06-02  0:30     ` Jeong Dal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8175246b-1260-1501-a37d-9e5ef8dbf29c@gmail.com \
    --to=henrimenke@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).