On 2013-02-20, at 10:08 PM, Bruno Dufour dufour@iro.umontreal.ca wrote:
On 2013-02-20, at 21:50, Marc Feeley feeley@iro.umontreal.ca wrote:
On 2013-02-20, at 8:06 PM, Bruno Dufour dufour@iro.umontreal.ca wrote:
On 20-02-2013, at 18:44 , Etienne Bergeron etienne.bergeron@gmail.com wrote:
Ruby and Javascript.... strange!
A lot of people of this list already know the JS part, but for the curious, here's the correct explanation :
http://stackoverflow.com/questions/9032856/what-is-the-explanation-for-these...
The [ ] + X part isn't that bad, but I have to admit that :
{ } + [ ] -> 0
while
var x = { }; var y = [ ] ; x + y -> "[object Object]"
is far from elegant.
Very strange! This is an even shorter example:
d8> ({})+[] [object Object] d8> {}+[] 0
but I don't quite understand this. It seems to be a bug in the REPL because:
d8> print( {}+[] ) [object Object] d8> print( ({})+[] ) [object Object]
In this case, { } cannot be parsed as an empty block because it is used as the argument to print, forcing it to be an expression. Therefore, it gets evaluated as a literal object. I don't think it's a bug in the REPL, but rather a quirk in the grammar.
I agree (now that I have read the original explanation). Indeed eval("{}+[]") returns 0.
Marc