lua-users home
lua-l archive

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

On Fri, 9 Aug 2019 at 10:15, Dennis Fischer <> wrote:
> To me it's the behavior of versions 5.2 and 5.3 that seems like a bug.

in 5.1 and before, any function declaration returns in a new function
object.  so they "feel" a bit like tables, where every "{}" creates a
new, different table.

in 5.2/3, if two functions are really identical, they're one and the
same.  so they "feel" a bit like strings, where two identical strings
are the same one (ignoring "large strings" (de)optimizations).

Of course, tables are mutable, so returning an old one would be total
chaos, while strings are immutable, so they behave as pure values.

Are functions mutable?  the code itself is immutable, the only mutable
things are the upvalues.  But if two functions share the same set,
then even if they're distinct, they would "change" together.  So it
makes sense to make them indistinct.

But so far, this has been considered mostly an optimization, not a
design feature.  So if it's more expensive than worth, could be
removed.   Or not.  Neither behaviour is a "bug".

personally, i do like the 5.2/3 behaviour.  seems more "pure".  but
relying on it is asking for trouble.  better be explicit and don't
repeat the definition if you want the function to be the same.