ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Re: metafun: error when I call the same function twice consecutively.
       [not found] <mailman.1.1527847201.14764.ntg-context@ntg.nl>
@ 2018-06-01 11:29 ` Jeong Dal
  2018-06-01 14:24   ` Alan Braslau
  0 siblings, 1 reply; 5+ messages in thread
From: Jeong Dal @ 2018-06-01 11:29 UTC (permalink / raw)
  To: list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl

Dear Henri Menke,

Thank you for the solution.
After inserting a line “save x, y;”, it works.

Thank you so much.

Best regards,

Dalyoung

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: metafun: error when I call the same function twice consecutively.
  2018-06-01 11:29 ` metafun: error when I call the same function twice consecutively Jeong Dal
@ 2018-06-01 14:24   ` Alan Braslau
  2018-06-02  0:30     ` Jeong Dal
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Braslau @ 2018-06-01 14:24 UTC (permalink / raw)
  To: Jeong Dal; +Cc: mailing list for ConTeXt users

On Fri, 01 Jun 2018 20:29:41 +0900
Jeong Dal <haksan@me.com> wrote:

> After inserting a line “save x, y;”, it works.

This is also defined as "clearxy ;"

For those learning MetaPost, simplifying, z is defined as "(x,y)" so
one can write
	z = (a,b) ;
This is an EQUATION in MetaPost
	(x,y) = (a,b) ;
not an assignment (as in most other languages), actually a pair of
equations:
	x = a ; y = b ;
When x and y are unknown, this can be "solved". When x and y contain
values, it leads to "inconsistent equations".

One *cannot* write
	z =: (a,b) ;
("=:" is the assignment operator),
for z is just a macro, not a "pair" object or variable.

This can be *very* confusing when learning MetaPost.

Alan

P.S.
	for i=0 upto n:
		z[i] = (i,0) ;
	endfor
works as each element of the (pseudo)array z is unknown, at least the
first time that it is used.
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: metafun: error when I call the same function twice consecutively.
  2018-06-01 14:24   ` Alan Braslau
@ 2018-06-02  0:30     ` Jeong Dal
  0 siblings, 0 replies; 5+ messages in thread
From: Jeong Dal @ 2018-06-02  0:30 UTC (permalink / raw)
  To: Alan Braslau,
	list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl

Dear Alan,

Thank you for the clear explanation about z.
I tought that z is a special variable different from other pairs.
Now, I know that it is an equation.

Thank you again.

Best regards,

Dalyoung

> 2018. 6. 1. 오후 11:24, Alan Braslau <braslau.list@comcast.net> 작성:
> 
> On Fri, 01 Jun 2018 20:29:41 +0900
> Jeong Dal <haksan@me.com> wrote:
> 
>> After inserting a line “save x, y;”, it works.
> 
> This is also defined as "clearxy ;"
> 
> For those learning MetaPost, simplifying, z is defined as "(x,y)" so
> one can write
> 	z = (a,b) ;
> This is an EQUATION in MetaPost
> 	(x,y) = (a,b) ;
> not an assignment (as in most other languages), actually a pair of
> equations:
> 	x = a ; y = b ;
> When x and y are unknown, this can be "solved". When x and y contain
> values, it leads to "inconsistent equations".
> 
> One *cannot* write
> 	z =: (a,b) ;
> ("=:" is the assignment operator),
> for z is just a macro, not a "pair" object or variable.
> 
> This can be *very* confusing when learning MetaPost.
> 
> Alan
> 
> P.S.
> 	for i=0 upto n:
> 		z[i] = (i,0) ;
> 	endfor
> works as each element of the (pseudo)array z is unknown, at least the
> first time that it is used.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: metafun: error when I call the same function twice consecutively.
  2018-06-01  2:22 ` Jeong Dal
@ 2018-06-01  3:19   ` Henri Menke
  0 siblings, 0 replies; 5+ messages in thread
From: Henri Menke @ 2018-06-01  3:19 UTC (permalink / raw)
  To: ntg-context



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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* metafun: error when I call the same function twice consecutively.
       [not found] <mailman.1.1527760801.30763.ntg-context@ntg.nl>
@ 2018-06-01  2:22 ` Jeong Dal
  2018-06-01  3:19   ` Henri Menke
  0 siblings, 1 reply; 5+ messages in thread
From: Jeong Dal @ 2018-06-01  2:22 UTC (permalink / raw)
  To: list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl
	ntg-context@ntg.nl

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

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-06-02  0:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <mailman.1.1527847201.14764.ntg-context@ntg.nl>
2018-06-01 11:29 ` metafun: error when I call the same function twice consecutively Jeong Dal
2018-06-01 14:24   ` Alan Braslau
2018-06-02  0:30     ` Jeong Dal
     [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 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).