From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: final thoughts on experiments with lua
Date: Thu, 10 Jan 2019 13:09:33 +0100 [thread overview]
Message-ID: <3857846d-3b97-90bf-d60d-d25d7674f729@xs4all.nl> (raw)
In-Reply-To: <5797F962-D863-48B1-B528-385C2F7DE2C5@fiee.net>
On 1/10/2019 12:11 PM, Henning Hraban Ramm wrote:
> Am 2019-01-10 um 10:50 schrieb luigi scarso <luigi.scarso@gmail.com>:
>
>>> sections = { “1”, “2”, “2a” }
>>>
>>> words = { [“1”] = { “a”, “b” },
>>> [“2a”] = { “c”, “d” } }
>>>
>>> so I can iterate through ipairs(sections) in sequence and pick up the word lists for each section. In the greater scheme of things, as Hraban pointed out: if there were an “ordered table” structure in Lua, this is precisely what it would do behind the scenes; it would just make it easier for the user.
>>>
>> the point is that I believe that is also doable in lua...
>> maybe could be helpful to have a significative example in python, ton see if we can mimic it in lua ?
>
> The "minimal example" in Python is a collections.OrderedDict. It’s not about ordering the entries (anew), but keeping the order, i.e. retrieving the entries in the same order as you added them. If you iterate over a Python dict or a Lua pairs table, the order can be arbitrary.
I'll add this:
local t = table.orderedhash()
t["1"] = { "a", "b" }
t["2"] = { }
t["2a"] = { "a", "c", "d" }
for k, v in table.ordered(t) do
print(k)
inspect(v)
end
which gives
1
table={
"a",
"b",
}
2
table={
}
3
table={
"a",
"c",
"d",
}
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2019-01-10 12:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-09 19:57 Thomas A. Schmitz
2019-01-09 20:12 ` luigi scarso
2019-01-09 20:38 ` Alan Braslau
2019-01-10 0:09 ` Hans Hagen
2019-01-10 0:08 ` Hans Hagen
2019-01-10 9:27 ` Schmitz Thomas A.
2019-01-10 9:50 ` luigi scarso
2019-01-10 11:11 ` Henning Hraban Ramm
2019-01-10 12:09 ` Hans Hagen [this message]
2019-01-10 14:53 ` luigi scarso
2019-01-10 7:03 ` Henning Hraban Ramm
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=3857846d-3b97-90bf-d60d-d25d7674f729@xs4all.nl \
--to=j.hagen@xs4all.nl \
--cc=ntg-context@ntg.nl \
/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).