lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Technically you never need more than one nesting level: Everything must
map to the natural numbers and vice versa in order to be computable by a
turing machine. A turing machine only requires a single "loop".

In practice, what's often done is to pack (x, y [, z]) coordinates into
an index i and having some auxiliary func to extract x, y [, z] from i
rather than requiring two (three) nested loops.

Using Lua's iterator construct, loop nesting could theoretically be
reduced by using iterator-composing functions like Python's itertools
(cartesian product, permutations, etc.).

On 29.07.22 16:58, Scott Morgan wrote:
On 29/07/2022 15:23, Lorenzo Donati wrote:
My scenario is about an algorithm that *inherently* needs some degree
of deep nesting to be efficient and more readable (some funky math
algos are that ways). So I assume that whoever has written the
implementation has already eliminated unneeded nesting levels and
what is left is the "most" clear and efficient implementation.

Out of interest, do you have any examples? The idea of needing these
awkward constructs makes my teeth itch, but I can believe there must
be some code that needs it.

Reveal the horrors please :)

Scott