lua-users home
lua-l archive

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


Quoth David Kastrup <dak@gnu.org>, on 2010-11-27 22:18:45 +0100:
> No, I couldn't.  It is just an observation that Lua has a tendency not
> to make you choose.  You don't pick between arrays and structures, for
> example.

That's because both can (abstractly) be treated as specific cases of
key-value mappings: a structure has a fixed set of symbolic keys, and
an array has a set of contiguous natural number keys starting from a
known point (for Lua, 1).

A function doesn't fit that notion very well, especially because these
aren't Haskellian "pure" functions but can also have side effects and
raise errors and so forth.  The only borderline case is that a pure
function (that's also a function in the mathematical sense) could be
considered a potentially infinite, lazy key-value mapping, but I think
this is a very strained association when comparing the uses of tables
and functions in most programs; there aren't many nontrivial cases
where they can be reasonably transposed.

> On a less bizarre tangent, I expect threads and functions to become the
> same eventually.

That makes slightly more sense in that a function encapsulates a
computation with entry and exit points, and a coroutine ("thread" in
Lua) can be considered a special case of a closure where the entry and
exit points vary between calls.  (This is stateful, but functions can
already close over and modify other private state, or public state.)
This already half-exists in the form of coroutine.wrap.

   ---> Drake Wilson