From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,MAILING_LIST_MULTI, MIME_HTML_MOSTLY autolearn=ham autolearn_force=no version=3.4.4 Received: from cgl.ntg.nl (Cgl.ntg.nl [5.39.185.202]) by inbox.vuxu.org (Postfix) with ESMTP id 135B9215B7 for ; Sat, 11 Jan 2025 22:12:20 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 32B08483FC9 for ; Sat, 11 Jan 2025 22:12:19 +0100 (CET) Authentication-Results: cgl.ntg.nl (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=ntg.nl DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ntg.nl; h= content-type:content-type:from:from:list-unsubscribe :list-subscribe:list-post:list-owner:list-help:list-archive :archived-at:list-id:subject:subject:reply-to:precedence :x-mailer:message-id:in-reply-to:references:date:date :mime-version:received:received:received:received:received :received; s=cgl; t=1736629938; x=1739221939; bh=6qwMIjhcfJ1QztJ aaX7uAd51VTjGAp/3gCpXgSxzHMs=; b=Cp6Ub8x4nReH5QAsM95A2Law19CkomZ mFysas1/z4iAyhLPv4iifM/Ox5ycUsDljDwRE7PLsQRUwQ0tQ8GHTJ212vLkLnRs b4rrsz1TWtuigdFXw9brIS/rv6JGTplZ3AQwRJZpWaqscIqdv98Zph6Yl59U4Yvq oVgdq+Tw+n88= X-Virus-Scanned: Debian amavisd-new at cgl.ntg.nl Authentication-Results: cgl.ntg.nl (amavisd-new); dkim=fail (2048-bit key) reason="fail (message has been altered)" header.d=mac.com Received: from cgl.ntg.nl ([127.0.0.1]) by localhost (cgl.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4w5SPWIAssu6 for ; Sat, 11 Jan 2025 22:12:18 +0100 (CET) Received: from cgl.ntg.nl (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 874064841BD for ; Sat, 11 Jan 2025 22:11:16 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 87BB34814A9 for ; Sat, 11 Jan 2025 22:11:01 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at cgl.ntg.nl Received: from cgl.ntg.nl ([127.0.0.1]) by localhost (cgl.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Hs07wBSKXxLa for ; Sat, 11 Jan 2025 22:11:00 +0100 (CET) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=17.58.23.191; helo=mr85p00im-hyfv06011401.me.com; envelope-from=haksan@mac.com; receiver= Received: from mr85p00im-hyfv06011401.me.com (mr85p00im-hyfv06011401.me.com [17.58.23.191]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cgl.ntg.nl (Postfix) with ESMTPS id 22C074811FE for ; Sat, 11 Jan 2025 22:10:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mac.com; s=1a1hai; t=1736629858; bh=jhCjfrVX/NzM/zxb4x6lceKpdC66iCW4pD+ZC4t7mV0=; h=From:Content-Type:Mime-Version:Subject:Date:To:Message-Id: x-icloud-hme; b=cf8sUeA0urlNEW20ZqBudy6adnKZ2XaAe1KxQCuXywCnTrozL09jYMYOQkKSeNkYC gc16jP2SymKInZ7mExnwYQ9uC3jtX2YBNoL3Btfn+jqq0JuLiO08skitkFPVmUgvVl ZUaPgiksqSvIF3Vp7o6QX6eogEzAalLrT57hr4DFpqC3if6wzf9pEHkHbyNOKz6XES oPyJJJ5obZK5yZ5N5F9UwVgHk0BlArPz+GJeibMp3mSc+BD6uub0rghJXWPptPApT8 Ek8JCWHRdJw+VFyxQ6azCPCbK5NBgJe7+CL6NZxW+FtCkrW1p8UOZJ4OkuFcymxGMs h79dKoKwUZSvA== Received: from smtpclient.apple (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-hyfv06011401.me.com (Postfix) with ESMTPSA id 462A3357AFD6 for ; Sat, 11 Jan 2025 21:10:54 +0000 (UTC) Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Date: Sun, 12 Jan 2025 06:10:52 +0900 References: <3D77A83F-3238-411E-BE8D-218EC4185D00@mac.com> To: mailing list for ConTeXt users In-Reply-To: Message-Id: <7A15DBAF-F424-41A4-BB9B-2F3CB1958CD4@mac.com> X-Mailer: Apple Mail (2.3654.120.0.1.15) X-Proofpoint-GUID: wDBzVYJEXDB7TZ4iEoyBVt6kR6zE3WQr X-Proofpoint-ORIG-GUID: wDBzVYJEXDB7TZ4iEoyBVt6kR6zE3WQr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-11_09,2025-01-10_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 adultscore=0 bulkscore=0 malwarescore=0 clxscore=1015 suspectscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501110182 Message-ID-Hash: KZTEF6FCK35CITXU4BRSWL3WQ2EL7DTL X-Message-ID-Hash: KZTEF6FCK35CITXU4BRSWL3WQ2EL7DTL X-MailFrom: haksan@mac.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list Reply-To: mailing list for ConTeXt users Subject: [NTG-context] Re: Lua question - table.save, table.load List-Id: mailing list for ConTeXt users Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Jeong Dal via ntg-context Cc: Jeong Dal Content-Type: multipart/mixed; boundary="===============0472466064750206797==" --===============0472466064750206797== Content-Type: multipart/alternative; boundary="Apple-Mail=_FEB0E452-0400-4A1D-8483-22F6EA561795" --Apple-Mail=_FEB0E452-0400-4A1D-8483-22F6EA561795 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Dear Hans, Thanks for the reply. >> The only way is to change the file name each time which is not good = to make a macro. >> Is there a way to clear the contents in the tempList.lua before I = save another table? >=20 > so you add to that list? >=20 I need more explanation. In the document.truthtable(), it saves the truth table of the defined = logic function to the file =E2=80=9CtempList.lua=E2=80=9D table.save("tempList.lua", tfList) Just after that I run \processMPbuffer[Kmap_***] In whch lua("MP =3D { } MP.data =3D table.load('tempList.lua')");=09 calls the contents of the tempList. I did this process several times using the different logic function as = following.=20 I want that the file =E2=80=9CtempList.lus=E2=80=9D contains the = current truth table value only not appending it to the last truth table = value. So I=E2=80=99d like to clear the contents of the tempList.lua after = loading it in MetaFun or before calling table.save("tempList.lua", = tfList) Of the new truth table tfList. I made a working example here. \startMPdefinitions numeric u,gap; numeric uk, wd, ht; % numeric tVal[][],a,b,c; string val[],codeOne[],codeTwo[]; uk :=3D LineHeight; wd :=3D 1.5uk; ht :=3D uk+5pt; def KmapFrameNew(expr first,second) =3D =20 codeOne[0] :=3D "0"; codeOne[1] :=3D "1"; codeTwo[0] :=3D "00"; codeTwo[1] :=3D "01"; codeTwo[2] :=3D "11"; codeTwo[3] :=3D "10"; % label rows label.top(textext("$" & first & "$"), (-.7wd,0)); label.top(textext("$" & second & "$"), (-.3wd,.5ht)); % drawing lines draw (-1.2wd,0) -- origin -- ((2*(length second)+1)*wd,0); draw (0, 1.1ht) -- origin -- (0,-(2*(length first)+.2)*ht); draw (-wd,ht) --origin; % label the rows=20 if (length first) =3D 1: for i =3D 0,1: label.top(textext(codeOne[i]), ((-.7wd, -(i+1)*ht))); endfor; else: for i =3D 0 upto 3: label.top(textext(codeTwo[i]), ((-.7wd, -(i+1)*ht))); endfor; fi; %label the columns if (length second) =3D 1: for i =3D 0,1: label.top(textext(codeOne[i]), ((i+1)*wd,.3ht)); endfor; else: for i =3D 0 upto 3: label.top(textext(codeTwo[i]), ((i+1)*wd,.3ht)); endfor; fi; =20 setbounds currentpicture to boundingbox currentpicture enlarged 2mm; draw boundingbox currentpicture; enddef; \stopMPdefinitions \startluacode function document.MakeHead(p,a) if not a then local t =3D p p =3D string.rep("|mcw(1cm)",#p-1) .. "|mcw(2cm)|" a =3D t end context.starttabulate { p } context.FL() for i=3D1,#a do context.NC() context(a[i]) end context.NC() context.NR() context.LL() end function document.MakeFooter() context.HL() context.stoptabulate() end local tf =3D {false, true } local tfList =3D {} local val =3D 0 function document.truthTable(a,func) document.MakeHead(a) for i,s in ipairs(tf) do for j,t in ipairs(tf) do for k,u in ipairs(tf) do context.NC() context(s and "1" or "0") context.NC() context(t and "1" or "0") context.NC() if #a =3D=3D 3 then break end context(u and "1" or "0") context.NC() val =3D func(s,t,u) and "1" or "0" context(val) context.NC() context.AR() table.insert(tfList, val) -- context(#tfList) end if #a =3D=3D 3 then val =3D func(s,t) and "1" or "0" context(val) context.NC() context.AR() table.insert(tfList, val) =20 end end end document.MakeFooter() table.save("tempList.lua", tfList) end \stopluacode \startbuffer[tbl:p2q] \startluacode function document.logicF(p,q) return ((not p) or q) end document.truthTable({ "x", "y", "x \\to y" },document.logicF) \stopluacode \stopbuffer \startbuffer[Kmap_p2qR] numeric n,u,k ; lua("MP =3D { } MP.data =3D table.load('tempList.lua')") ; lua("mp.print('n :=3D ',\#MP.data)") ; KmapFrameNew("p","q") for i =3D 0,1: for j =3D 1,2: label.top(textext(lua("MP.data[" & decimal (2*i+j) & = "]")),(j*wd,-(i+1)*ht)); endfor; endfor; draw unitsquare xyscaled (1wd,2ht) shifted (1.5wd,-2.1ht) withpen = pencircle scaled 2pt withcolor .625blue ; draw unitsquare xyscaled (1.8wd,ht) shifted (.6wd,-1.1ht) withpen = pencircle scaled 2pt withcolor .625red ; \stopbuffer \startbuffer[tbl:ABC] \startluacode function document.logicF(p,q,r) return (not p) and (not(p and r) or q) end document.truthTable({ "A", "B", = "C","(\\overbar{AC}+B)\\overbar{A}"},document.logicF) \stopluacode \stopbuffer \startbuffer[Kmap_ABCR] lua("MP =3D { } MP.data =3D table.load('tempList.lua')") ; numeric n,k ;=20 %lua("mp.print('n :=3D ',\#MP.data)") ; KmapFrameNew("A","BC") for i =3D 0,1: k :=3D 1; for j =3D 1,2,4,3: label.top(textext(lua("MP.data[" & decimal (4*i+j) & = "]")),(k*wd,-(i+1)*ht)); k :=3D k + 1;=20 endfor; endfor; draw unitsquare xyscaled (3.6wd,ht) shifted (.7wd,-1.1ht) withpen = pencircle scaled 2pt withcolor .625red ; \stopbuffer \startbuffer[tbl:xyz] \startluacode function document.logicF(p,q,r) return (not q) and (p or r) end document.truthTable({ "x", "y", "z","f(x,y,x)"},document.logicF) \stopluacode \stopbuffer \startbuffer[Kmap_xyzR] lua("MP =3D { } MP.data =3D table.load('tempList.lua')") ; numeric n,k ; KmapFrameNew("x","yz") for i =3D 0,1: k :=3D 1; for j =3D 1,2,4,3: label.top(textext(lua("MP.data[" & decimal (4*i+j) & = "]")),(k*wd,-(i+1)*ht)); k :=3D k + 1;=20 endfor; endfor; draw unitsquare xyscaled (1wd,2ht) shifted (1.5wd,-2.1ht) withpen = pencircle scaled 2pt withcolor .625blue ; draw unitsquare xyscaled (1.8wd,1ht) shifted (.6wd,-2.1ht) withpen = pencircle scaled 2pt withcolor .625red ; \stopbuffer \starttext \startplacetable[] {\startcombination[distance=3D1.5cm,2*1] {\getbuffer[tbl:p2q]}{=EC=A7=84=EB=A6=AC=ED=91=9C} {\processMPbuffer[Kmap_p2qR]}{K-map} \stopcombination} \stopplacetable \startplacetable[] {\startcombination[distance=3D1.5cm,2*1] {\getbuffer[tbl:ABC]}{=EC=A7=84=EB=A6=AC=ED=91=9C} {\processMPbuffer[Kmap_ABCR]}{K-map} \stopcombination} \stopplacetable \startplacetable[location=3Dhere,reference=3Dtbl:Fxyz] {\startcombination[distance=3D1.5cm,1*2] {\getbuffer[tbl:xyz]}{} {\processMPbuffer[Kmap_xyzR]}{} \stopcombination} \stopplacetable \stoptext --Apple-Mail=_FEB0E452-0400-4A1D-8483-22F6EA561795 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Dear = Hans,

Thanks for the = reply.

The = only way is to change the file name each time which is not good to make = a macro.
Is there a way to clear the contents in the = tempList.lua before I save another table?

so you add to that = list?

I need more = explanation.

In = the document.truthtable(), it saves the truth table of the defined logic = function to the file =E2=80=9CtempList.lua=E2=80=9D

table.save("tempList.lua", = tfList)

Just after that I = run
= \processMPbuffer[Kmap_***]
In whch
lua("MP =3D { } MP.data =3D = table.load('tempList.lua')"); =
calls the contents of the = tempList.
I did this process several times using = the different logic function as following. 

I want that  the file = =E2=80=9CtempList.lus=E2=80=9D contains the current truth table value = only not appending it to the last truth table value.
So I=E2=80=99d like to clear the contents of the tempList.lua = after loading it in MetaFun or before calling table.save("tempList.lua", tfList)
Of the new truth table tfList.

I made a working example = here.

\startMPdefinitions
numeric = u,gap;
numeric uk, wd, ht;
% = numeric tVal[][],a,b,c;
string val[],codeOne[],codeTwo[];

uk :=3D LineHeight;
= wd :=3D 1.5uk;
ht :=3D uk+5pt;

def KmapFrameNew(expr first,second) =3D
=
codeOne[0] :=3D "0";
codeOne[1] :=3D = "1";
codeTwo[0] :=3D "00";
codeTwo[1] :=3D = "01";
codeTwo[2] :=3D "11";
codeTwo[3] :=3D = "10";
% label rows
label.top(textext("$" & first & = "$"), = (-.7wd,0));
label.top(textext("$"= & second & "$"), (-.3wd,.5ht));
% drawing lines
draw (-1.2wd,0) -- origin -- ((2*(length second)+1)*wd,0);
draw (0, 1.1ht) -- origin -- (0,-(2*(length first)+.2)*ht);
draw (-wd,ht) --origin;
% label the rows =
if (length first) =3D 1:
for i =3D = 0,1:
label.top(textext(codeOne[i]), ((-.7wd, -(i+1)*ht)));
endfor;
else:
for i =3D 0 upto = 3:
label.top(textext(codeTwo[i]), ((-.7wd, -(i+1)*ht)));
endfor;
fi;
%label the columns
= if (length = second) =3D = 1:
for i =3D 0,1:
= label.top(textext(codeOne[i]), ((i+1)*wd,.3ht));
endfor;
else:
for i =3D 0 upto = 3:
label.top(textext(codeTwo[i]), ((i+1)*wd,.3ht));
endfor;
fi;
setbounds currentpicture to = boundingbox currentpicture enlarged 2mm;
draw = boundingbox currentpicture;
enddef;
\stopMPdefinitions

\startluacode
function document.MakeHead(p,a)
if not a then
local t =3D p
p =3D string.rep("|mcw(1cm)",#p-1) .. "|mcw(2cm)|"
a =3D t
end
context.starttabulate { p }
context.FL()
for i=3D1,#a do
context.NC() context(a[i])
end
context.NC() context.NR()
context.LL()
end
function document.MakeFooter()
context.HL()
context.stoptabulate()
= end

local tf =3D {false, true }
local tfList =3D {}
local val =3D 0
function document.truthTable(a,func)
document.MakeHead(a)
for i,s in ipairs(tf) do
for j,t in ipairs(tf) do
for k,u in ipairs(tf) do
context.NC()
= context(s and "1" or "0")
context.NC()
context(t and "1" or "0")
context.NC()
if #a =3D=3D 3 then
break
end
context(u and "1" or "0")
context.NC()
val =3D func(s,t,u) and "1" or "0"
context(val)
= context.NC()
context.AR()
table.insert(tfList, val)
-- context(#tfList)
= end
if #a =3D=3D 3 then
val =3D func(s,t) and "1" or "0"
context(val)
context.NC()
context.AR()
table.insert(tfList, val) =
end
end
end
document.MakeFooter()
table.save("tempList.lua", = tfList)
end
\stopluacode

\startbuffer[tbl:p2q]
\startluacode
function document.logicF(p,q)
return ((not p) or q)
end
document.truthTable({ "x", "y", "x \\to y" },document.logicF)
\stopluacode
\stopbuffer

\startbuffer[Kmap_p2qR]
numeric n,u,k ;

lua("MP =3D { } MP.data =3D table.load('tempList.lua')") ;
lua("mp.print('n :=3D ',\#MP.data)") ;

KmapFrameNew("p","q")
for i =3D 0,1:
for j =3D 1,2:
label.top(textext(lua("MP.data[" & decimal = (2*i+j) & "]")),(j*wd,-(i+1)*ht));
endfor;
endfor;
draw unitsquare xyscaled (1wd,2ht) shifted (1.5wd,-2.1ht) withpen pencircle scaled 2pt withcolor .625blue = ;
draw unitsquare xyscaled (1.8wd,ht) shifted (.6wd,-1.1ht) withpen pencircle scaled 2pt = withcolor .625red ;
\stopbuffer

\startbuffer[tbl:ABC]
\startluacode
= function = document.logicF(p,q,r)
return (not p) and (not(p and r) or q)
end
document.truthTable({ "A", "B", "C","(\\overbar{AC}+B)\\overbar{A}"},document.logicF)
\stopluacode
\stopbuffer

\startbuffer[Kmap_ABCR]
lua("MP =3D { } MP.data =3D table.load('tempList.lua')") ;
numeric n,k ; =
%lua("mp.print('n :=3D ',\#MP.data)") ;

KmapFrameNew("A","BC")
for i =3D 0,1:
k :=3D 1;
for j =3D = 1,2,4,3:
label.top(textext(lua("MP.data[" & decimal (4*i+j) & "]")),(k*wd,-(i+1)*ht));
k :=3D k + 1;
endfor;
endfor;
draw unitsquare xyscaled (3.6wd,ht) shifted (.7wd,-1.1ht) withpen pencircle scaled 2pt withcolor .625red = ;
\stopbuffer

\startbuffer[tbl:xyz]
\startluacode
function document.logicF(p,q,r)
return (not q) and (p or r)
end
document.truthTable({ "x", "y", "z","f(x,y,x)"},document.logicF)
\stopluacode
\stopbuffer

\startbuffer[Kmap_xyzR]
lua("MP =3D { } MP.data =3D table.load('tempList.lua')") ;
numeric n,k ;

KmapFrameNew("x","yz")

for i =3D = 0,1:
k :=3D 1;
for j =3D= 1,2,4,3:
label.top(textext(lua("MP.data[" & decimal (4*i+j) & "]")),(k*wd,-(i+1)*ht));
k :=3D k + 1;
endfor;
endfor;
draw unitsquare xyscaled (1wd,2ht) shifted (1.5wd,-2.1ht) withpen pencircle scaled 2pt withcolor .625blue = ;
draw unitsquare xyscaled (1.8wd,1ht) shifted (.6wd,-2.1ht) withpen pencircle scaled 2pt = withcolor .625red ;
\stopbuffer

\starttext
\startplacetable[]
{\startcombination[distance=3D1.5cm,2*1]
{\getbuffer[tbl:p2q]}{=EC=A7=84=EB=A6=AC=ED=91=9C}
{\processMPbuffer[Kmap_p2qR]}{K-map}
\stopcombination}
\stopplacetable

\startplacetable[]
{\startcombination[distance=3D1.5cm,2*1]
{\getbuffer[tbl:ABC]}{=EC=A7=84=EB=A6=AC=ED=91=9C}
{\processMPbuffer[Kmap_ABCR]}{K-map}
\stopcombination}
\stopplacetable

\startplacetable[location=3Dhere,reference=3Dtbl:Fxyz]
{\startcombination[distance=3D1.5cm,1*2]
{\getbuffer[tbl:xyz]}{}
{\processMPbuffer[Kmap_xyzR]}{}
\stopcombination}
\stopplacetable
\stoptext

= --Apple-Mail=_FEB0E452-0400-4A1D-8483-22F6EA561795-- --===============0472466064750206797== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror) archive : https://github.com/contextgarden/context wiki : https://wiki.contextgarden.net ___________________________________________________________________________________ --===============0472466064750206797==--