lua-users home
lua-l archive

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

On Wednesday, July 8, 2015, Dirk Laurie <> wrote:
2015-07-07 0:13 GMT+02:00 Coda Highland <>:
> A large proportion of the tuple users I've met are Python converts.

2015-07-08 2:34 GMT+02:00 Tim Hill <>:
> You can think of them as an aggregate constant.

Very well put.

I'll confess to being an apostate from Python myself, but this is not
really a Python thing. Even C89 has constant arrays (ie tuples) and
structures (ie aggregate constants).

The main reason why aggregate constants would be nice to have in
Lua is that more lurking bugs can be caught at compile time.

This is one of those invaluable bonus threads. I've heard OF tuples but I didn't know what they were and I still don't comprehend their apparent significance. If anyone (on or off list) would like to point me to their favorite "Why Should I care about Tuples" document, please do. I've been googling it with "okay" results. 

I don't think I saw this earlier, but given the following:

function Tuple(...)
  local co = coroutine.wrap(function (...) while true do coroutine.yield(...) end end )
  return co, co(...) 

t = Tuple("foo", 5)


This start is missing a way for two Tuple objects with the same arguments to be evaluated as equal.

Beyond that, there is nothing about them that implies that I should be able to, for example, add them, or whatever?

And so also... If I can modify a value in a tuple, then the result would be a new tuple:

--assuming some Tuple library.... == 10
t2 = t:set("foo", 5) == 5
t2 ~= t == 10

And so a Tuple might be any object that produces a new object if it is modified? (or errors?)[1]

The benefit being an object that behaves like a basic type, when it comes to equality?

Lua strings are tuples, correct? 

I should use them In places where I would otherwise need to do deep inspection, etc.?

In other languages, tuples may hint a compiler or otherwise provide efficiency benefits?

If the above is correct, I may only be missing the ability to recognize when I should reach for them.[2]


[1]LHF made an int64 library for Lua 5.2 that worked like this and it confused me at first. 

[2]Canonical examples would be welcomed (especially if they include negative examples (where their absence hurts or where they might be misapplied)