Dear all,

I draw Pascal’s triangle with the label of each point created by using lua 
As you see in the code below, I defined fact(n) and combi(n,r) using lua.
For the calculation tt, I used two different methods.
Both are working well when I run the given code.

But I got an error, when I added this code to a ConTeXt file composed product 
and components,
and using the second method, i.e. combi(n,r). The first method is still working 
The error message is as following:

metapost log    > loading metafun, including version 1.004 for metafun 
iv and xl
metapost log    > 
luatex warning  > mplib: run script: [string "return mp.print(combi(0,0 ))"]:1: 
attempt to call a nil value (global 'combi')

metapost log    > >> tt
metapost log    > >> vacuous
metapost log    > ! Equation cannot be performed (numeric=vacuous).
metapost log    > <to be read again> 
metapost log    >                    ;
metapost log    > <for(0)> ...&decimal(0)&","&decimal(EXPR0)&" ))");
metapost log    >                                                   
metapost log    > <for(0)>;;endfor
metapost log    >                                                   ; ENDFOR
metapost log    > <*>; draw now -- (now+B); endfor; endfor
metapost log    >                                                   ;;

I don’t know why the same code treated differently.
I think that I have to do something more in luacode which I don’t know.
Comments are wellcome!

Best regards,



function fact (n)
  if n <= 0 then
    return 1
    return n * fact(n-1)
function combi(n,r)
   return fact(n)/(fact(r)*fact(n-r))
numeric n,r,s,u,dx,dy,tt; u := 1.8cm;
path p, q;
pair A,B,start,now;
A := dir(210)*u;
B := dir(-30)*u;
dy := sind(30)*u;
dx := 2*cosd(30)*u;
for n=0 upto 4:
   start := n*dir(210)*u;
   for r=0 upto n:
      s := n-r;
%     tt := lua("mp.print(fact(" & decimal n & ")/(fact(" & decimal r & 
")*fact(" & decimal s &" )))");
      tt := lua("mp.print(combi(" & decimal n & "," &  decimal r & " ))");
      now := start+r*right*dx;"$\displaystyle {" & decimal n & "\choose" & decimal 
r & "} = "& decimal tt & "$"),now);
      draw now -- (now+A);
      draw now -- (now+B);

If your question is of interest to others as well, please add an entry to the 

maillist : /
webpage  : /
archive  :
wiki     :

Reply via email to