From: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>
To: Otared Kavian <otared@gmail.com>
Cc: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: [NTG-context] Re: Question about building an array of values with Lua
Date: Thu, 24 Aug 2023 21:43:23 +0200 [thread overview]
Message-ID: <f720ab63-ab4e-1c66-8d45-ce182b7215eb@gmail.com> (raw)
In-Reply-To: <0D8E23FE-0CC5-4D07-AD38-566AF5F7326A@gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 1891 bytes --]
Otared Kavian schrieb am 24.08.2023 um 12:50:
>
>> On 24 Aug 2023, at 06:03, Wolfgang Schuster
>> <wolfgang.schuster.lists@gmail.com
>> <mailto:wolfgang.schuster.lists@gmail.com>> wrote:
>>> […]
>>
>> I would drop the column check in this case.
>>
>> for i = 0,9 do
>> context.startxrow()
>> context.startxcell()
>> context(i)
>> context.stopxcell()
>> context.startxcell()
>> context(math.mod(i*i,10))
>> context.stopxcell()
>> context.startxcell()
>> context(i)
>> context.stopxcell()
>> context.startxcell()
>> context(math.mod(2*i*i,10))
>> context.stopxcell()
>> context.stopxrow()
>> end
>>
>> Wolfgang
>
> Indeed this is much more elegant… It feels so good to be on this list
> and learn from such insights :-)
We don't even need the math.mod function because Lua added with version
5.1 a modulo operator,
the loop to create the row can now be changed to
for i = 0,9 do
context.startxrow()
context.startxcell()
context(i)
context.stopxcell()
context.startxcell()
context(i * i % 10)
context.stopxcell()
context.startxcell()
context(i)
context.stopxcell()
context.startxcell()
context(2 * i * i % 10)
context.stopxcell()
context.stopxrow()
end
Wolfgang
[-- Attachment #1.2: Type: text/html, Size: 3119 bytes --]
[-- Attachment #2: Type: text/plain, Size: 495 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2023-08-24 19:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-23 17:28 [NTG-context] " Fabrice Couvreur
2023-08-23 15:48 ` [NTG-context] " Wolfgang Schuster
2023-08-23 23:04 ` Otared Kavian
2023-08-24 4:03 ` Wolfgang Schuster
2023-08-24 10:50 ` Otared Kavian
2023-08-24 19:43 ` Wolfgang Schuster [this message]
2023-08-25 12:47 ` Fabrice Couvreur
2023-08-24 11:15 ` Fabrice Couvreur
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f720ab63-ab4e-1c66-8d45-ce182b7215eb@gmail.com \
--to=wolfgang.schuster.lists@gmail.com \
--cc=ntg-context@ntg.nl \
--cc=otared@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).