# May I return more results than specified?

I'm golfing in Lua, which does support such thing as multiple return values like this:

function multret()
return 1, 'hello'
end

local a,b = multret()
-- a is 1, b is 'hello'
local c = multret()
-- c is 1
print(multret())
-- print "1<tab>hello"
local tab = {multret()}
-- create table (array) containing all returned results (equal to {1, 'hello'})


Now, my problem exactly: there is library function string.gsub whose result I directly return from my function. This lead to two values being returned from my submission: resulting string (answer required) and amount of replacements done.

Is it fine to return garbage values after required results? I think so, because assigning them to value (like in my example with variable c) will lead to same result, just want to be sure. In other words, would my multret function be a valid answer to challenge asking to "create function which return 1"?

• I think it will depend on the challenge. Usually, the use case is to print the exact result of the func call, and in this case it won't be a good answer => you'll have to return only what's needed. But I don't have every single case in my mind right now so there might be cases where it is okay to return something unrelated to the answer. – V. Courtois Aug 9 at 11:35
• I'm not familiar with Lua, is it correct that the amount of outputs is basically determined from the "outside" (i.e. when you call the function you have to decide how many outputs you want to get)? If so I think MATLAB has a similar feature. – flawr Aug 9 at 12:05
• @flawr Yes, with pretty much default option to pass them all. – val says Reinstate Monica Aug 9 at 12:48
• @flawr I've extended question with more examples when result amount is kept unchanged. – val says Reinstate Monica Aug 9 at 12:53
• Pretty sure we have a consensus on this under default I/O that disallows this. But there's never any harm in asking, on a per challenge basis, whether your output format is permissible. – Shaggy Aug 9 at 22:08
• These kinds of functions, when used as a value, have the value of the first returned thing, e.g. here. I'd imagine then that for challenges, the first returned value could be considered its return value – Conor O'Brien Aug 10 at 23:12
• So in that case, this would be like a Prolog or Brachylog answer which could be interpreted as generating a list of values, or interpreted as only returning the first. – Unrelated String Aug 28 at 20:37