lua-users home
lua-l archive

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

On Sun, May 23, 2010 at 8:42 AM, Mark Hamburg <> wrote:
> Does this mean that the compiler could now detect functions without upvalue references and treat them as constants so that we don't reconstruct them over and over again? (The presence of function environments stood in the way of doing so in the past.)
> Today, one could lift such definitions out of the code and explicitly store them in local variables, but doing so can break the flow of the code for reading.

While on the subject of cheap closures, I thought having a way to
signal an object (closure or table) is a "constant" and should only be
created when the Function is being loaded (the prototype is created).
Something like this:

string.gsub(s, ".", @function(a) --[[ ... ]] end)

So the above would create the pattern function when the above chunk is
loaded. The code would simply index the "constant" closure when
calling string.gsub. (A better name would probably be Singleton
instead of constant.)

Ideally this would also work for tables as well.

- Patrick Donnelly