lua-users home
lua-l archive

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


Am 09.07.2015 um 16:38 schröbte Andrew Starks:

For my education on tuples, I'd be helped if someone could provide a real
world application that would be done more simply with tuples and would be
difficult, otherwise. As is, they seem like a way to deal with a lack of
multiple return values... Or multiple return values seem like a good-enough
way to do many of the things that tuples do.

Tuples are nice whenever you want to put aggregate data structures into a set or as keys into a map, e.g. complex numbers, points, vectors, parsed URLs, persons (first name, last name, address, age, ...). Actually, relations (database tables) are sets of tuples. You can use tuples as the basis for arbitrary objects (just like tables) if you want the objects to have value semantics instead of reference semantics. Whenever you have defined an `__eq` metamethod on a table, you probably wanted a tuple in the first place.

Of course you can also use tuples instead of multiple return values, but that is just a hack, IMHO.


-Andrew


Philipp