lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 3/10/19 17:57, Roberto Ierusalimschy wrote:
With hindsight, I sometimes regret that when we introduced booleans in
Lua, decades ago, we did not change the standard error return "nil, msg"
to "false, msg". If nil is some kind of "absent value", it is weird that
"msg" comes after something that is not there.

So, the motivation for the change is to move our minds from the
concept that errors return (nil,msg) to the concept that errors return
(falsy,msg). Maybe one day in the distant future we might change
that falsy to false instead of nil.

The classic way still makes lots of sense to me. false is something you can perfectly expect from a function, just as any other value. There are a lot of functions where you pass data and ask if some property is true or false: is_prime(n), button_pressed(b), in_bounding_box(p,b), etc. Even pcall fits this pattern, because you are asking if the function you passed can be executed successfully.

The "weird" return is nil, because I interpret it as "could not produce a value to return". If we look at it with Pascal eyes, it looks like a broken function call because it could not provide a return.


Jorge