From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/106826 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Jeong Dal Newsgroups: gmane.comp.tex.context Subject: running lua in metafun and in ConTeXt Date: Sat, 11 Apr 2020 21:32:45 +0900 Message-ID: References: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Content-Type: multipart/mixed; boundary="===============1989942341960153403==" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="40454"; mail-complaints-to="usenet@ciao.gmane.io" To: "list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl" Original-X-From: ntg-context-bounces@ntg.nl Sat Apr 11 14:33:21 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jNFK4-000APE-Au for gctc-ntg-context-518@m.gmane-mx.org; Sat, 11 Apr 2020 14:33:20 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 579CC183245; Sat, 11 Apr 2020 14:32:54 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ltp6rFgPT321; Sat, 11 Apr 2020 14:32:53 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 5B31D18324C; Sat, 11 Apr 2020 14:32:53 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 827A6183244 for ; Sat, 11 Apr 2020 14:32:52 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rXhGIz45Hyvy for ; Sat, 11 Apr 2020 14:32:51 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=17.58.6.53; helo=pv50p00im-ztbu10011701.me.com; envelope-from=haksan@me.com; receiver= Original-Received: from pv50p00im-ztbu10011701.me.com (pv50p00im-ztbu10011701.me.com [17.58.6.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 9F3E81831E5 for ; Sat, 11 Apr 2020 14:32:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1586608369; bh=FaIce17CC+qZTcQMz0mKaB9OLqasUUKlMXNnSqKHOgM=; h=From:Content-Type:Subject:Date:To:Message-Id; b=DZhFrZ3Pj89qn3WdFEKB+phbxpfxL5hLG+ASB3VPKn3YteAuVcp5yIRwJvg1QNuLJ NNzWU6V0Mxnu4kFO6oYkgSLZ4SxKMExkpyYlElbEX3KwiZHoYiasU8BQQHJ97Ki2UE C3oZHiqNAqWvLLGj0UAbgZD7a196eZWF/uSTCG8fbqC+Uzg7q6y2IB+YHX3bPG4w4a gpRsaKEpMZ2r3FQ9XFQAXhb+F7mlL7Gvm/EyxeTIf2sesuUiIT9/1XTu+cR73+W9Gv KU4SQ2QWsW1YV1h2/DEyye6MVU+1NTZrm3y8vFxDKWAmkkmDty9nuOq56GSLOb7VvN ynVjHE4qLxNTQ== Original-Received: from [10.0.1.6] (unknown [222.232.154.22]) by pv50p00im-ztbu10011701.me.com (Postfix) with ESMTPSA id 2205C8A03D3 for ; Sat, 11 Apr 2020 12:32:47 +0000 (UTC) In-Reply-To: X-Mailer: Apple Mail (2.3608.80.23.2.2) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.676 definitions=2020-04-11_04:2020-04-09, 2020-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=665 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2002250000 definitions=main-2004110119 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:106826 Archived-At: --===============1989942341960153403== Content-Type: multipart/alternative; boundary="Apple-Mail=_3D657487-0093-4CD4-95C6-8799C59CB102" --Apple-Mail=_3D657487-0093-4CD4-95C6-8799C59CB102 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Dear all, I draw Pascal=E2=80=99s triangle with the label of each point created by = using lua functions. 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 well. The error message is as following: metapost log > loading metafun, including plain.mp version 1.004 for = metafun iv and xl metapost log >=20 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=3Dvacuous). metapost log > =20 metapost log > ; metapost log > ...&decimal(0)&","&decimal(EXPR0)&" ))"); metapost log > = now:=3Dstart+(EXPR0)*right*d... metapost log > ....now--(now+A);draw.now--(now+B);endfor metapost log > ; = ENDFOR metapost log > <*> ...now+A); draw now -- (now+B); endfor; endfor metapost log > ;; I don=E2=80=99t know why the same code treated differently. I think that I have to do something more in luacode which I don=E2=80=99t = know. Comments are wellcome! Best regards, Dalyoung %%%%%%% \startluacode function fact (n) if n <=3D 0 then return 1 else return n * fact(n-1) end end function combi(n,r) return fact(n)/(fact(r)*fact(n-r)) end \stopluacode \startbuffer[fig121] numeric n,r,s,u,dx,dy,tt; u :=3D 1.8cm; path p, q; pair A,B,start,now; A :=3D dir(210)*u; B :=3D dir(-30)*u; dy :=3D sind(30)*u; dx :=3D 2*cosd(30)*u; for n=3D0 upto 4: start :=3D n*dir(210)*u; for r=3D0 upto n: s :=3D n-r; % tt :=3D lua("mp.print(fact(" & decimal n & ")/(fact(" & decimal r = & ")*fact(" & decimal s &" )))"); tt :=3D lua("mp.print(combi(" & decimal n & "," & decimal r & " = ))"); =20 now :=3D start+r*right*dx; dotlabel.top(textext("$\displaystyle {" & decimal n & "\choose" & = decimal r & "} =3D "& decimal tt & "$"),now); draw now -- (now+A); draw now -- (now+B); endfor; endfor; \stopbuffer \starttext \switchtobodyfont[11pt] \processMPbuffer[fig121] \switchtobodyfont[12pt] \stoptext --Apple-Mail=_3D657487-0093-4CD4-95C6-8799C59CB102 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Dear all,

I draw = Pascal=E2=80=99s triangle with the label of each point created by using = lua functions.
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 well.
The error = message is as following:

metapost log    > loading = metafun, including plain.mp 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=3Dvacuous).
metapost log    > = <to be read again> 
metapost log   =  >                 =    ;
metapost log    > = <for(0)> ...&decimal(0)&","&decimal(EXPR0)&" = ))");
metapost log    >     =                     =                     =       now:=3Dstart+(EXPR0)*right*d...
metapost log    > <for(0)> = ....now--(now+A);draw.now--(now+B);endfor
metapost = log    >               =                     =                 ; = ENDFOR
metapost log    > <*> = ...now+A); draw now -- (now+B); endfor; endfor
metapost log    >         =                     =                     =   ;;

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

Best regards,

Dalyoung

%%%%%%%

\startluacode
function = fact (n)
= if n = <=3D 0 then
= return 1
else
= return n * fact(n-1)
end
end
function combi(n,r)
return fact(n)/(fact(r)*fact(n-r))
end
\stopluacode
\startbuffer[fig121]
numeric = n,r,s,u,dx,dy,tt; u :=3D= 1.8cm;
path p, q;
pair = A,B,start,now;
A :=3D dir(210)*u;
B :=3D dir(-30)*u;
dy :=3D sind(30)*u;
dx :=3D 2*cosd(30)*u;
for n=3D0 upto 4:
start = :=3D n*dir(210)*u;
for r=3D0 upto n:
s :=3D = n-r;
% tt = :=3D lua("mp.print(fact(" & decimal n & ")/(fact(" & decimal r & ")*fact(" & decimal s &"= )))");
tt :=3D= lua("mp.print(combi(" & decimal n & "," = & decimal r & " ))");
= now :=3D = start+r*right*dx;
= dotlabel.top(textext("$\displaystyle {" = & decimal n & "\choose" & decimal r & "} = =3D "& decimal tt & "$"),now);
draw now -- (now+A);
draw now -- (now+B);
endfor;
endfor;
\stopbuffer
\starttext
\switchtobodyfont[11pt]
\processMPbuffer[fig121]
\switchtobodyfont[12pt]
\stoptext

= --Apple-Mail=_3D657487-0093-4CD4-95C6-8799C59CB102-- --===============1989942341960153403== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============1989942341960153403==--