lua-users home
lua-l archive

Re: Arithmetic on strings

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


On 13-6-2012 19:14, liam mail wrote:
On 13 June 2012 17:35, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
Any performance-conscious code that uses
coercion in critical pathes deserves what it gets
It could be said anyone that updates to 5.2.* deservers what they get.
So I take it that if coercion is removed then string concatenation
would use the '+' operator[1] and Lua programmes would become more
complicated[2] or are these views now outdated?
Liam
[1] http://www.lua.org/doc/hopl.pdf
One of the few (and rather minor) innovations in Lua was
the syntax for string concatenation. The natural ‘+’ operator
would be ambiguous, because we wanted automatic coercion of strings to
numbers in arithmetic operations.
[2] http://www.lua.org/semish94.html
This coercion is useful because it simplifies programs and avoids the
need for explicit conversion functions.
What precisely are we talking about?
(1) 1 + "2" (- * / etc)
(2) 1 .. "2"
(3) concat({1,"2"})
(4) format("%s",1)
I suppose only in the first case automatic conversion is unwanted? Actually I can imagine that a future concat does a tostring if needed so that { 1, "2", true } also works.
Hans
-----------------------------------------------------------------
 Hans Hagen | PRAGMA ADE
 Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
 tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-----------------------------------------------------------------

AltStyle によって変換されたページ (->オリジナル) /