[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Concatenating strings with '+'
- From: Ignacio Burgueño <ignacio@...>
- Date: Wed, 20 Jul 2005 19:10:45 -0300
> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br
> [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Ben
> Sunshine-Hill
> Sent: Wednesday, July 20, 2005 6:04 PM
> To: Lua list
> Subject: Re: Concatenating strings with '+'
>
> No, it isn't possible. Consider this construction:
>
> function foo(a,b)
> return a+b
> end
>
> Q: Are a and b strings or not? A: There's no way to know.
> This is what's known as "static type analysis", and is only
> possible for dynamically typed languages in special cases.
>
> There's a good reason why + doesn't concatenate in Lua: to
> avoid accidentally concatenating when you really meant to
> add. Since numbers can be used in a string context and vice
> versa, this would generate quite a few problems. Stick to ..
> for concatenation.
>
> Ben
I totally agree with you that sticking with .. to concatenate is the best,
but I need to allow the + operator to be used with strings because I need to
run some old propietary code which uses constructs like that and I'm trying
to avoid rewriting it. Anyway, I managed to allow this, just needed to do
some ugly things in luaV_execute. I hope that this thing doesn't blow up in
my face.
Regards,
Ignacio