lua-users home
lua-l archive

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

> On Jul 5, 2015, at 8:59 AM, steve donovan <> wrote:
> On Sun, Jul 5, 2015 at 2:39 PM, Jay Carlson <> wrote:
>> Could I call a function like table.append(c, 4)?
> I think the idea of a tuple is that it is a const unmodifiable table.
>> I had a more complicated proposal for "static" which might help. "static c = Const{1,2,3}" would do the same thing, even inside a loop.
> So it would be a _compile-time_ constant? That makes it cheap to use,
> although restricts what values it can be initialized to

But in Lua constants have nearly identical overhead to locals (in fact, you can think of them conceptually as read-only locals). Look carefully at the bytecode and the only real difference is a bit indicating if the source is a local (on the stack) or a constant (in the constant table for the chunk).

Apart from the original OP issue of efficient memoization, I’m not really seeing anything in this thread that cannot already be done in Lua with appropriate tables and metatables, or a few good practices (use of locals etc).