lua-users home
lua-l archive

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




On 16/01/2015 22:38, Roberto Ierusalimschy wrote:
Is there a reason why the coercion first recognizes the string as
representing an int and then "throws away" that info and converts it
unconditionally into a float?

We want a fast track for integers, so the first check is simply whether
both operands are integers. After that check, it is too cumbersome to
recheck whether the strings are "integers" and then also do an integer
operation.

-- Roberto


Thanks for the clarification!

I'm not really sure, maybe I just must get used to it, but the whole string->number automatic coercion thing seems to have become a bit overcomplicated. I only relied a few times on this behavior before (pre 5.3), so I wouldn't miss it should you remove it from the language and raise an error whenever a string is used where a number is expected. As it stands now the feature seems to me a bit counterintuitive or at least too convoluted and perhaps can cause more harm than good. Just a gut feeling, though. (my 2c)

Cheers!

-- Lorenzo