lua-users home
lua-l archive

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




On Wed, Nov 19, 2014 at 2:43 AM, Tim Hill <drtimhill@gmail.com> wrote:
>
> 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


Anyone can answer this, but for my own edification:


I've been using Lua 5.3 since Alpha 1. With regards to number and their subtypes, we have not run into any issues that have been surprising, except unexpected '1.0' pretty printing.

The examples that have been provided here have been clear, but to my understanding they've also been somewhat academic. Are there some real-world, practical examples that could be provided?

I ask because I wonder if those examples would bring to light other factors that might be considered. For instance, if the examples involve bit shifting or advanced math, it might be reasonable to expect those people to dive a bit deeper into the tool. If the use cases are more mundane, then perhaps this would lend more weight to addressing it?




-Andrew

I sheepishly add last post script:

If this is "specified behavior" that one would have to emulate if they were making a Lua implementation, then it does seem somewhat less... compact? than the rest of the Language's specification. It seems that, so long as 'subtype' is not a formalized concept that is consistently applied and also available for use by the programmer, any solution will be an abstraction that leaks and therefore open to endless debate. As it is, "subtype" is a concept that you can *mostly* forget about, which are, in my world view, the worst kind of concepts.

The peanut gallery has spoken.