Is there any better way to golf this (other than removing newlines/indentation)?

  local c=s(a,b)
  local d=c
  for i,v in ipairs{...} do d=d:push(v) end
  return c

I'm particularly bothered by the double local usage, but as Lua does not have multiple assignment, and I cannot use function parameters to declare the locals, I can't see a way to remove them.

For those who care, this is the implementation of the __call metamethod in my quick hack of a linked-list ~class used in this answer.

  • \$\begingroup\$ Lua does have multiple assignment: lua.org/manual/5.1/manual.html#2.4.3 \$\endgroup\$ – nolan Aug 26 '16 at 23:39
  • \$\begingroup\$ That's parallel, assignment, though. See this question. You cannot use it to share values. \$\endgroup\$ – Phrogz Aug 26 '16 at 23:40
  • 1
    \$\begingroup\$ Could you perhaps declare both variables in the same line and then do assignment later? Like local c,d=s({v=b},a),0 d=c? That takes out one of the local keywords. I don't know anything about Lua, though. \$\endgroup\$ – Value Ink Aug 26 '16 at 23:45
  • \$\begingroup\$ Yes that can be done. \$\endgroup\$ – nolan Aug 26 '16 at 23:49
  • \$\begingroup\$ @ValueInk Post that as an answer! Note that you don't need the ,0. \$\endgroup\$ – Phrogz Aug 27 '16 at 0:55

As requested in the comments, here it is as an answer.

local c,d=s(a,b)  -- d is nil

This saves you one local declaration, should give you -5 bytes.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.