[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.3.0 (work1) now available
- From: Tomas Guisasola Gorham <tomas@...>
- Date: Mon, 8 Jul 2013 16:43:11 -0300 (BRT)
Hi Roberto
Anyway, since tostring() in Lua 5.3 will produce different
string representations for integer and floating-point numbers (can I
assume that?) it won't be more useful to have "*i" format to read "1.0"
and convert it to the integer 1 ?
Useful to whom? If I am reading a list of integer numbers, probably I
do not want to accept 1.0.
Useful to anyone reading a file produced with an earlier version
of Lua. Well, at least I think it would be useful. As I said, I don't
have that exactly problem.
The main (only?) reason why Lua has *n for reading is for performance,
to avoid creating an intermediate string for each number it reads.
Anything smarter than fscanf("%lld") or similar will have some impact on
performance, not to mention that the implementation is tricky. We have
to read the entire numeral as a string, to see whether it is a float or
an integer, and then do the conversion. We must be very careful not to
read too much in cases such as 1.0e-x (must stop before the 'e-x') and
other strange cases.
I see. I was talking about performance also.
Any reading option will never be smart enough to guess (and do)
exaclty what we want. (Do we want to accept 1.0 or only 1? What
about 1.1, should it be accepted and rounded? What about hexa-decimal
formats? Scientific notation?) There are too many variations. Sometimes
we have to write code...
I am not arguing that my proposed alternative (reading a float
and converting it to an integer) would solve all problems, of course not.
I was just guessing that it would be more useful to some people moving
from previous versions to the new one. Anyway, your argument about the
implementation complexity is good enough to change my mind :-)
Regards,
Tomás