satyr / coco

Unfancy CoffeeScript
http://satyr.github.com/coco/
MIT License
497 stars 48 forks source link

`x <?= y` should return `x` when `x <= y` #178

Closed copygirl closed 12 years ago

copygirl commented 12 years ago

(was x <?= y not the same as x = x <? y)

I'm not quite sure what exactly is going on here, but I expected these two to behave the same.

satyr commented 12 years ago

x gets the lower value in both cases. The compound version is compiled so that the assignment only happens when necessary (just like x ||= y compiles to x || (x = y) rather than x = x || y).

copygirl commented 12 years ago
x = 0
y = Math.random! * 10 - 5
x <?= y

always returns y.

x = x <? y on the other hand only returns y when it's smaller than 0.

vendethiel commented 12 years ago

x <?= y will return y, but assigns x correctly.

satyr commented 12 years ago

Oh, the return value. Yup, that's a bug.