4 ms·
> Lua is not weakly typed (at least not in the sense of Javascript and PHP where "3"+4 is either 7 or 34, can't remember which. In JS, "3" + 4 is "34", in PHP,
by TazeTSchnitzel 11y ago
> Lua is not weakly typed (at least not in the sense of Javascript and PHP where "3"+4 is either 7 or 34, can't remember which.
In JS, "3" + 4 is "34", in PHP, it's 7. PHP separates concatenation and addition, unlike JS.
Anyway, huh? Lua has automatic type conversion. That's usually considered weak typing.
- JoshuaScholar 11y agoIn Lua "3"+4 is an error. Concatenation is a different operator than add, specifically to avoid confusing coersions.
- ggilles 11y agoTry it: Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio > ="3" + 4 7
- JoshuaScholar 11y agoAh. Well at least there isn't a confusion between add and concat "3"+4 is 7 4.."3" is "43" "3hello"+4 is an error
- beagle3 11y agoStand corrected with the example. I forgot about the lua auto type conversion - but that, on its own does not make weak typing - Python, C and Java do that between floats and ints, would you consider them weak typed? I'm not familiar with a rigorous definition of weak typing - but my experience is that weak typing is usually reserved for languages like TCL, Snobol, and even Perl where there's no "type" of values to speak of - everything is equivalent and decoded according to context.
- superfunc 11y agoThat's the problem with those terms, both 'weak' and 'strong' typing are purely subjective.
- ufo 11y agoIts just for "+" and ".." though. For other things, such as equality and table indexing numbers and strings are not interchangeable.