7
Is there any better way to golf this (other than removing newlines/indentation)?
function(a,b,...)
local c=s(a,b)
local d=c
for i,v in ipairs{...} do d=d:push(v) end
return c
end
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.
Lua does have multiple assignment: https://www.lua.org/manual/5.1/manual.html#2.4.3
– nolan – 2016-08-26T23:39:24.437That's parallel, assignment, though. See this question. You cannot use it to share values.
– Phrogz – 2016-08-26T23:40:31.6731Could 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 thelocal
keywords. I don't know anything about Lua, though. – Value Ink – 2016-08-26T23:45:49.227Yes that can be done. – nolan – 2016-08-26T23:49:23.523
@ValueInk Post that as an answer! Note that you don't need the
,0
. – Phrogz – 2016-08-27T00:55:02.027Does
s
have side effects? If not I guess you could dolocal c,d=s(a,b),s(a,b)
. – feersum – 2016-08-27T03:08:13.097@feersum Good question. Yes,
s()
creates a table and returns it. The shared value is a reference to an element, not a simple value. – Phrogz – 2016-08-27T03:12:35.003