lua-users home
lua-l archive

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


On Wed, Aug 12, 2009 at 9:38 PM, Peter Cawley wrote:
> The second part is for expanding expressions in expression lists. In
> terms of pseudo code, this transforms expression lists like "e1, e2
> ..., e3, ..." into "e1, detuple(tuple(e2), e3, ...)", though tuple and
> detuple are VM opcodes rather than functions. The TUPLE opcode takes 2
> or more stack values, copies them to a new tuple data array area of a
> lua_State, and replaces them with a single value which points to the
> new position of the values in the tuple array. The DETUPLE opcode
> expands zero or more tuples back into the stack.

One of the prototypical problems in [1] was to implement a function this:

  --Wraps a function with trace statements.
  function trace(f)
    return function(...)
      print("begin", f)
      local result = tuple(f(...))
      print("end", f)
      return result()
    end
  end

Could we add new keywords that correspond with the TUPLE/DETUPLE
opcodes to achieve something like the above?

[1] http://lua-users.org/wiki/VarargTheSecondClassCitizen