lua-users home
lua-l archive

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

On Wed, Nov 20, 2013 at 11:04 AM, Pierre Chapuis <> wrote:
I consider defining a map() function and using it with pure functions (e.g. tostring) idiomatic.

I think it would be more idiomatic to have it replace the table's content in-place, leaving it up to the caller to copy the table or not before modifying it. But then we face a recurring problem: it's surprisingly hard to agree on a general proper way to copy a table in Lua.

A simple way to generate containers almost functionally, but in a way idiomatically compatible with imperative code, is to use containers-by-comprehension, as in Haskell, Python or Metalua. GvR had a passionate argument once: he wanted to remove lambda/map/fold from Python 3, because half of the time a list by comprehension would be as short and more readable, and the other times the map/lambda/fold contraption was unreadable and unmaintainable, something he tries to actively ban from Python, through opinionated language design and coding conventions.

Folding is a different matter: it takes a container but doesn't produce a container as a result (in the general case); therefore the question of modifying the list doesn't occur.

(Here's how it could look like in Lua: