lua-users home
lua-l archive

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


> 
> A very common question from beginners (and most "average scripters")
> runs like this:
> 
>> a = 1/3 - 1
>> print((a + 1) * 3 == 1)
>   --> false                ??????????????????????????
> 
> We have had this happening since the very first version of Lua. Scripters
> do not know what is going on. They ask, they learn. Good for them.
> 
> -- Roberto
> 


I completely agree. My only point has been that the fewer “gotchas” a language has the easier it is to learn and use. Consistent syntax. Consistent API/library style. Consistent behavior. As the Ruby guys say, “minimize surprises” (which, imho, Ruby utterly fails to do).

The point of my original post was that the sub-types of “number" in Lua 5.3 make the number type more complex than before, and that it *might* actually be simpler to not try to hide the sub-types inside number but to simply have two different types. I didn’t say it should be done, i was just speculating. However, I don’t see how you could explain my earlier example without going into the details of integers vs floating point, so in a way there ARE two types; they are just hidden within the “number” type. After all, this will require some explaining as well:

i = 1
a = i / 1
print(i, a)

On a purely personal level I would find it easier to explain “you can use integral floating point values whenever an integer is required” rather than try to pretend they were the same type and later explain why some numbers have very different semantics to others; it also makes more sense of the error message flagged by the OP. That was all I was saying in my earlier post; not a big deal imho.

—Tim