5 ms·
What's an example of a language that, when adding two strings/chars, parses them as integers first?
by matchu 12y ago
What's an example of a language that, when adding two strings/chars, parses them as integers first?
- sp332 12y agoIn perl you use + for addition and . for concatenation. So '3' + '4' converts the strings to integers and returns an integer, and 3 . 4 converts them to strings first and returns a string.
- marcosdumay 12y agoPerl. Altough its adition only apply to numbers, so that would be a bad example, it does automaticaly interpret digit strings as numbers.
- manveru 12y agoHow about TCL? % expr "3" + "4" 7 % expr "3" + 4 7 % expr 3 + 4 7
- NhanH 12y agoIn addition to the answer of Perl and TCL, PHP would too, since the concatenate operator in PHP is "." - any dynamic and/or weak typing language that doesn't overload "+" for string concatenation will probably behave the same way.
- _pmf_ 12y ago> What's an example of a language that, when adding two strings/chars, parses them as integers first? The cancerous piece of shit we know as Javascript.
- croddin 12y agoNo, Javascript will concatenate two strings that contain integers if you add them. "1"+"1" //=> "11"
- notduncansmith 12y agoAs 'croddin pointed out, this is flat-out wrong - and that attitude is hardly conducive to a constructive discussion.