|
I'd say it would decrease predictability and readability. I'm not aware of any language that treats "," as vararg concatenation. Some languages have special "spread" operators. Lua simply declares that all returns of last item of an explist are preserved to make multiple value returns usable. Back to your example: If both f() and g() return varargs and the varargs are concatenated, it'd make for very unreadable code. You'd always have to know the arities of all function calls inside an explist ("h(f(), g())", "{f(), g()}", "a, b, c = f(), g()"). With the current implementation, you can always match one value on the LHS to one exp on the RHS, except for superfluous values on the LHS, which Lua matches to additional return values on the RHS. With your proposed change, this wouldn't be possible anymore. Tools like luacheck couldn't help you if you had too many or too few values on the LHS. On 27.07.22 12:02, Rodrigo Azevedo wrote:
Dear, I'm wondering why we can't use multiple returns in expressions like local a,b,c = f(),g() Why not stack the result of the expressions on the right side and name the ordered resulting values accordingly? Detailed: Suppose Lua 5.4 changes such that local f = function() return 1,2 end local g = function() return 3 end and local a,b,c,d = f(),g() would simply do a=1,b=2,c=3,d=nil instead of the current a=1,b=3,c=nil,d=nil. Moreover, the same on function arguments s(f(),g()) -> calls s(1,2,3) instead of s(1,3). Would it be more convenient and predictable? best, Rodrigo