lua-users home
lua-l archive

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




On 14/07/16 09:22 AM, Egor Skriptunoff wrote:
On Thu, Jul 14, 2016 at 2:01 PM, Philipp Janda <siffiejoe@gmx.net <mailto:siffiejoe@gmx.net>> wrote:

    Am 14.07.2016 um 10:13 schröbte Egor Skriptunoff:

        On Thu, Jul 14, 2016 at 11:01 AM, Daurnimator
        <quae@daurnimator.com <mailto:quae@daurnimator.com>> wrote:


                Maybe, {1, 2, 3} for tables, @{1, 2, 3} for arrays
                (with array metatable
                applied)?


            In that case, why not use the already valid: S(1,2,3)

        Three reasons:
        1) Standardization of array type in Lua (all the developers
        will use the
        same implementation of arrays)
        2) Avoidance of performance penalty due to passing vararg to a
        function


What performance penalty?

Lua pushes all the arguments to the stack to invoke S(1,2,3),
and inside S() Lua pushes them AGAIN for constructing a table.
"VARARG" bytecode is not O(1) instruction, it was discussed earlier in this list.

That's only true for PUC Lua. That is,

local function array(...)
  local function arrayco(...)
    while true do coroutine.yield(...) end
  end
  local co = coroutine.wrap(arrayco)
  co(...)
  return co
end

is usable in sane Lua implementations. Stop using the PUC Lua interpreter and you won't have any more complaints about this stuff.


Moreover, S(1,2,3) does not work for arrays longer than 256 elements.

    `f@{ 1, 2, 3 }` isn't that much better, though ...

Quite nice with a space between :-)
func @{1,2,3}


--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.