Open aleclarson opened 6 years ago
This is definitely something I miss from Python; however, I do think it should compile to if 1 < x and x < 2
- definitely a nitpick, but I think it'd help with debugging/looking at compiled code.
Definitely what @RyanSquared said, it also prevents surprised with overloaded operators. Should cache the middle one as well, in case it has side-effects.
Right so it'd compile to local _comparison_0 = x ; if 1 < _comparison_0 and _comparison_0 < 2
.
The local
declaration is only necessary if doing x.y
or x!
, or could x
really have a side effect?
It actually is necessary. Example:
setmetatable(_ENV, {__index = coroutine.wrap(function()
local n = 1
while true do
coroutine.yield(n)
n = n + 1
end
end)})
print(a, a, a)
Now, if you do this yourself, why. However, it still is a side effect.
Touché.
This is a nitpick, but maybe _cmp_0
would be a more concise (yet just as clear?) name for the compiled result. ¯\(ツ)/¯
(side note: I've never seen such a snarky looking shrug)
And yeah, that was just a quick example; I'd be fine with _cmp_0
given how popular "cmp" is as a shortening of the word, not that it should matter much outside of debugging anyways.
..would compile to: