From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/88317 Path: news.gmane.org!not-for-mail From: luigi scarso Newsgroups: gmane.comp.tex.context Subject: Re: Lua to Context Table Date: Sat, 2 Aug 2014 03:23:56 +0200 Message-ID: References: <278633B4-13E7-48B2-94C3-A49610130862@inradius.net> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0559111672==" X-Trace: ger.gmane.org 1406942666 4800 80.91.229.3 (2 Aug 2014 01:24:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 2 Aug 2014 01:24:26 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sat Aug 02 03:24:20 2014 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([5.39.185.229]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XDO3X-0007SM-Oh for gctc-ntg-context-518@m.gmane.org; Sat, 02 Aug 2014 03:24:19 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 46A641029E for ; Sat, 2 Aug 2014 03:24:19 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id iCgxhRbn7IWs for ; Sat, 2 Aug 2014 03:24:19 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id D35D210222 for ; Sat, 2 Aug 2014 03:24:09 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 51CB2101E6 for ; Sat, 2 Aug 2014 03:24:05 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 3Eu57y0SJL1I for ; Sat, 2 Aug 2014 03:24:00 +0200 (CEST) Original-Received: from filter1-utr.mf.surf.net (filter1-utr.mf.surf.net [195.169.124.152]) by balder.ntg.nl (Postfix) with ESMTP id 2DADF101E2 for ; Sat, 2 Aug 2014 03:24:00 +0200 (CEST) Original-Received: from mail-pa0-x22a.google.com (mail-pa0-x22a.google.com [IPv6:2607:f8b0:400e:c03::22a]) by filter1-utr.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id s721NrGf024881 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Sat, 2 Aug 2014 03:23:55 +0200 Original-Received: by mail-pa0-f42.google.com with SMTP id lf10so6761465pab.29 for ; Fri, 01 Aug 2014 18:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=/4Sjbx4SycuRgFg46j1Ov/ljFEDMsdN+U+3cXqKsWZM=; b=myifgc3Edr/zfv5Sp2j6tj52JFA3QOlGYJVbQvLslcZl3JYW6dspLRMXG6SWnhXTEt 2Cp0EOyWXE73kxZij+RZBenQqsnywilBl/7N1hR+wK0K8qclnAq6HeE11axkgj5IXEHt X4WO354CKPCpFp7+mjgSPatUb+XjmOH+K3bQFXKqXKiiyJSndytXJ3qKYpYQoi0L/I74 k93u7uwuRqiSvrgv5/24fdPSzXy6KrOOK4E4eZfI1PVvuQ0eLi4eTI+N9eZpJugrRALt pQw+qLQ0iZZm6DNXRJXvqBad+XFbR+gZ1XnZ6BHxjWRSVgOwpUIt2jVY91Tl5GPOf3fG k9Uw== X-Received: by 10.70.96.38 with SMTP id dp6mr87911pdb.136.1406942636903; Fri, 01 Aug 2014 18:23:56 -0700 (PDT) Original-Received: by 10.70.7.36 with HTTP; Fri, 1 Aug 2014 18:23:56 -0700 (PDT) In-Reply-To: <278633B4-13E7-48B2-94C3-A49610130862@inradius.net> X-Bayes-Prob: 0.0001 (Score 0, tokens from: ntg-context@ntg.nl, base:default, @@RPTN) X-CanIt-Geo: ip=2607:f8b0:400e:c03::22a; country=US X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 07MxBnTH1 - 8b8e7bade28a - 20140802 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.14 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-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:88317 Archived-At: --===============0559111672== Content-Type: multipart/alternative; boundary=001a11c1d18017936704ff9b5c79 --001a11c1d18017936704ff9b5c79 Content-Type: text/plain; charset=UTF-8 On Sat, Aug 2, 2014 at 12:59 AM, John Kitzmiller wrote: > Here is Lua code that prints the first nine fibonacci numbers: > > local function fib(n) > f={1,1} > for i=3,9 do > f[i]=f[i-1]+f[i-2] > end > return(f[n]) > end > for n=1,9 do print(fib(n)) end > > Here is Context+Lua that prints 3 x 3 table of the first nine natural > numbers: > > \starttext > \setupTABLE[each][each][frame=off,align=left,width=4em,height=2em] > \startluacode > context.bTABLE() > for j = 0, 2 do > context.bTR() > for k = 1, 3 do > context.bTD() > context(3*j+k) > context.eTD() > end > context.eTR() > end > context.eTABLE() > \stopluacode > \stoptext > > How can these be combined to print a 3 x 3 table of the first nine > fibonacci numbers? > > I have tried a couple of ways to iterate over the lua table f in the most > indented line of context, looked at what pertinent threads I could find, > the Wiki entries, CLD, and tried Aditya's method from Stack Exchange; I am > missing something. > You have a *global* table f that collides with the internals of context local function fib(n) f={1,1} for i=3,9 do f[i]=f[i-1]+f[i-2] end return(f[n]) end \starttext \setupTABLE[each][each][frame=off,align=left,width=8em,height=2em] \startluacode local function fib(n) local f={1,1} for i=3,9 do f[i]=f[i-1]+f[i-2] end return(f[n]) end context.bTABLE() for j = 0, 2 do context.bTR() for k = 1, 3 do context.bTD() context("fib(%s)=%s" ,3*j+k, fib(3*j+k) ) context.eTD() end context.eTR() end context.eTABLE() \stopluacode \stoptext -- luigi --001a11c1d18017936704ff9b5c79 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable



On Sat, Aug 2, 2014 at 12:59 AM, John Kitzmiller = <kitz@inradius.ne= t> wrote:
Here is Lua code that prints the first nine fibonacci numb= ers:

local function fib(n)
=C2=A0 f=3D{1,1}
=C2=A0 for i=3D3,9 do
=C2=A0 =C2=A0 f[i]=3Df[i-1]+f[i-2]
=C2=A0 end
=C2=A0 return(f[n])
end
for n=3D1,9 do print(fib(n)) end

Here is Context+Lua that prints 3 x 3 table of the first nine natural numbe= rs:

\starttext
\setupTABLE[each][each][frame=3Doff,align=3Dleft,width=3D4em,height=3D2em]<= br> \startluacode
context.bTABLE()
for j =3D 0, 2 do
=C2=A0 context.bTR()
=C2=A0 =C2=A0 for k =3D 1, 3 do
=C2=A0 =C2=A0 =C2=A0 context.bTD()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 context(3*j+k)
=C2=A0 =C2=A0 =C2=A0 context.eTD()
=C2=A0 =C2=A0 end
=C2=A0 context.eTR()
end
context.eTABLE()
\stopluacode
\stoptext

How can these be combined to print a 3 x 3 table of the first nine fibonacc= i numbers?

I have tried a couple of ways to iterate over the lua table f in the most i= ndented line of context, looked at what pertinent threads I could find, the= Wiki entries, CLD, and tried Aditya's method from Stack Exchange; I am= missing something.

You have a *global* table f =C2= =A0that collides with the internals of context=C2=A0
local f= unction fib(n)
=C2=A0 f=3D{1,1}
=C2=A0 for i=3D3,9 do
=C2=A0 =C2=A0 f[i]=3Df[i-1]+f[i-2]
=C2=A0 end
=C2=A0 return(f[n])
end


\starttext
\setupTABLE[each][each]= [frame=3Doff,align=3Dleft,width=3D8em,height=3D2em]

\startluacode
local function fib(n)
=C2=A0 local f=3D{1,1}
=C2= =A0 for i=3D3,9 do
=C2=A0 =C2=A0 f[i]=3Df[i-1]+f[i-2]
= =C2=A0 end
=C2=A0 return(f[n])
end
context.bT= ABLE()
for j =3D 0, 2 do
=C2=A0 context.bTR()
=C2=A0 =C2=A0 for k =3D 1, 3 do
=C2=A0 =C2=A0 =C2=A0 context.bTD()
=C2=A0 =C2=A0 =C2=A0 =C2=A0= context("fib(%s)=3D%s" ,3*j+k, fib(3*j+k) )
=C2=A0 =C2= =A0 =C2=A0 context.eTD()
=C2=A0 =C2=A0 end
=C2=A0 conte= xt.eTR()
end
context.eTABLE()
\stopluacode
\stopt= ext

--
luigi
--001a11c1d18017936704ff9b5c79-- --===============0559111672== 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 / 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 ___________________________________________________________________________________ --===============0559111672==--