Re: Replacing the "if" statement with an "if" expression which supersedes it
"'Sewbacca' via lua-l" <[email protected]> Fri, 26 Jun 2026 15:42:46 +0200
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <[email protected]> |
I have seldomly the need for a true ternary operator, and almost always I can swap "a and b or c" to "not a and c or b". But it does happen that both values can be falsy in which case a true ternary operator would be useful.
I have mixed feelings about the if x then a else[if y then] b end syntax where the last value of blocks a and b are possible return values.
If Lua went down that road I would also want those semantics for the do ... end block as well, but probably not for loops and certainly not for function return values (those should be explicit).
Allthough I could be persuaded that loops are multi return blocks:
local x, y = for i = 1, 2 do
i * i
end
local t = { for line in io.lines(".bash_history") end }
Okay maybe loops as multi return values wouldn't be that bad but I can't imagine implicit return statements for function blocks would be a good idea:
function export.login(user)
login(user, getsecret(user)) -- might leak critical information
end
~ Sewbacca
--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/087e7207-f476-4f40-b53e-68e49ed811cf%40kolabnow.com.