[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Patch to remove auto-casting between numbers and strings
- From: Asko Kauppi <askok@...>
- Date: Sat, 9 Sep 2006 11:30:07 +0300
Perhaps having to do with this:
> _,_,a= string.find( "100", "(%d+)" )
I've always wanted a "(%d+)" caption to give me a number, not a string.
John Belmonte kirjoitti 9.9.2006 kello 4.01:
Reuben Thomas wrote:
Motivation for the patch: I don't like automatic casting; it hides
I also think it rarely helps users, and if it does (e.g. in a
file), then you can do the auto-casting yourself (e.g. read a config
file, and call "to<type>(v)" on each value you read).
For example, print is one function I've left alone. This is an
example of the fine line in Lua between auto-casting and
calling a tostring method.
Nice to know that I'm not the only one who dislikes the implicit
coercion-- however I don't think the line you mention is that
print function is intended for debugging (e.g. dumping a given
and it makes sense to call tostring() on its arguments. That's a
documented behavior performed explicitly by the function, and very
different from the implicit coercion taking place in an expression
(5 + "5").
To resolve Mark's issue with string.format in another post, I think
existing %s should run tostring() on its argument. There's no want or
need for a strict string format type.