* metafun- how to pass array as an argument
@ 2011-01-24 12:18 dalyoung
2011-01-24 12:50 ` Peter Rolf
0 siblings, 1 reply; 4+ messages in thread
From: dalyoung @ 2011-01-24 12:18 UTC (permalink / raw)
To: ntg-context
Dear all,
I draw a simple figure using the code as below.
In the code, I use "for i = 3,5,0,2,1,7:" in def draw_balls.
However, if I can pass the array "3,5,0,2,1,7" as an argument for def draw_balls (expr n) and call draw_balls (3,5,0,2,1,7), then it can be used for different number of balls and number of boxes.
Is there a way to do that or any suggestions?
Thank you for reading.
Regards,
Dalyoung
\startbuffer[a]
path p;
numeric bwidth, u, lastpoint;
u :=1cm;
p := fullcircle scaled .3u;
lastpoint := 0;
def draw_balls = %(expr s)
draw (0,0) -- (0, u);
for i=3,5,0,2,1,7:
for j = 1 upto i:
draw p shifted (lastpoint+.32*j*u,.3u);
endfor;
bwidth := .32i*u+.5u;
draw (lastpoint,0) -- (lastpoint +bwidth,0) -- (lastpoint +bwidth,u);
lastpoint := lastpoint+bwidth;
endfor;
enddef;
draw_balls;
\stopbuffer
\starttext
\processMPbuffer[a]
\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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: metafun- how to pass array as an argument
2011-01-24 12:18 metafun- how to pass array as an argument dalyoung
@ 2011-01-24 12:50 ` Peter Rolf
2011-01-24 13:26 ` Peter Rolf
0 siblings, 1 reply; 4+ messages in thread
From: Peter Rolf @ 2011-01-24 12:50 UTC (permalink / raw)
To: mailing list for ConTeXt users
Am 24.01.2011 13:18, schrieb dalyoung:
> \startbuffer[a]
> path p;
> numeric bwidth, u, lastpoint;
> u :=1cm;
> p := fullcircle scaled .3u;
> lastpoint := 0;
>
> def draw_balls = %(expr s)
def draw_balls(text s) =
> draw (0,0) -- (0, u);
> for i=3,5,0,2,1,7:
for i=s:
> for j = 1 upto i:
> draw p shifted (lastpoint+.32*j*u,.3u);
> endfor;
> bwidth := .32i*u+.5u;
> draw (lastpoint,0) -- (lastpoint +bwidth,0) -- (lastpoint +bwidth,u);
> lastpoint := lastpoint+bwidth;
> endfor;
> enddef;
>
> draw_balls;
>
> \stopbuffer
>
> \starttext
> \processMPbuffer[a]
> \stoptext
works in mkii, but fails in mkiv. i use an outdated version (31.12.2010)
here.
! LuaTeX error <main ctx instance>:1: attempt to call field 'feedback'
(a nil value)
stack traceback:
<main ctx instance>:1: in main chunk.
<argument> ....feedback("\currentMPgraphicname ")}
\processMPgraphic ...ntMPgraphicformat ", \!!bs #1
;\!!es , \!!bs
\currentMPi...
<argument> ...feedback("\currentMPgraphicname ")}}
\endMPgraphicgroup
\secondoftwoarguments #1#2->#2
l.25 \processMPbuffer[a]
?
best wishes, Peter
___________________________________________________________________________________
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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: metafun- how to pass array as an argument
2011-01-24 12:50 ` Peter Rolf
@ 2011-01-24 13:26 ` Peter Rolf
0 siblings, 0 replies; 4+ messages in thread
From: Peter Rolf @ 2011-01-24 13:26 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1: Type: text/plain, Size: 1935 bytes --]
Am 24.01.2011 13:50, schrieb Peter Rolf:
> Am 24.01.2011 13:18, schrieb dalyoung:
>> \startbuffer[a]
>> path p;
>> numeric bwidth, u, lastpoint;
>> u :=1cm;
>> p := fullcircle scaled .3u;
>> lastpoint := 0;
>>
>> def draw_balls = %(expr s)
> def draw_balls(text s) =
>
>> draw (0,0) -- (0, u);
>> for i=3,5,0,2,1,7:
> for i=s:
>
>> for j = 1 upto i:
>> draw p shifted (lastpoint+.32*j*u,.3u);
>> endfor;
>> bwidth := .32i*u+.5u;
>> draw (lastpoint,0) -- (lastpoint +bwidth,0) -- (lastpoint +bwidth,u);
>> lastpoint := lastpoint+bwidth;
>> endfor;
>> enddef;
>>
>> draw_balls;
>>
draw_balls(3,5,0,2,1,7)
sorry, i forgot to change this line.
example code is attached for testing...
>> \stopbuffer
>>
>> \starttext
>> \processMPbuffer[a]
>> \stoptext
>
> works in mkii, but fails in mkiv. i use an outdated version (31.12.2010)
> here.
>
>
> ! LuaTeX error <main ctx instance>:1: attempt to call field 'feedback'
> (a nil value)
> stack traceback:
> <main ctx instance>:1: in main chunk.
> <argument> ....feedback("\currentMPgraphicname ")}
>
> \processMPgraphic ...ntMPgraphicformat ", \!!bs #1
> ;\!!es , \!!bs
> \currentMPi...
> <argument> ...feedback("\currentMPgraphicname ")}}
> \endMPgraphicgroup
> \secondoftwoarguments #1#2->#2
>
> l.25 \processMPbuffer[a]
>
> ?
>
>
> best wishes, Peter
> ___________________________________________________________________________________
> 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://tex.aanhet.net
> archive : http://foundry.supelec.fr/projects/contextrev/
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
>
[-- Attachment #2: test.tex --]
[-- Type: text/plain, Size: 494 bytes --]
\startbuffer[a]
path p;
numeric bwidth, u, lastpoint;
u :=1cm;
p := fullcircle scaled .3u;
lastpoint := 0;
def draw_balls(text s) =
draw (0,0) -- (0, u);
for i=s:
for j = 1 upto i:
draw p shifted (lastpoint+.32*j*u,.3u);
endfor;
bwidth := .32i*u+.5u;
draw (lastpoint,0) -- (lastpoint +bwidth,0) -- (lastpoint +bwidth,u);
lastpoint := lastpoint+bwidth;
endfor;
enddef;
draw_balls(3,5,0,2,1,7);
\stopbuffer
\starttext
\processMPbuffer[a]
\stoptext
[-- Attachment #3: Type: text/plain, Size: 486 bytes --]
___________________________________________________________________________________
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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: metafun- how to pass array as an argument
@ 2011-01-24 13:33 dalyoung
0 siblings, 0 replies; 4+ messages in thread
From: dalyoung @ 2011-01-24 13:33 UTC (permalink / raw)
To: ntg-context
Dear Peter,
Thank you for your help.
By changing (expr s) to (text s), it works!
I am using ConTeXt Minimal and the luatex version is "This is LuaTeX, Version beta-0.61.0-2010072816"
Thank you again.
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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-01-24 13:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-24 12:18 metafun- how to pass array as an argument dalyoung
2011-01-24 12:50 ` Peter Rolf
2011-01-24 13:26 ` Peter Rolf
2011-01-24 13:33 dalyoung
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).