2 ms·
Lua has tail call optimization (and is otherwise very similar to Python). function even(x) if x == 0 then return true else return o
by silentbicycle 18y ago
Lua has tail call optimization (and is otherwise very similar to Python).
function even(x)
if x == 0 then
return true
else
return odd(x - 1)
end
end
function odd(x)
if x == 0 then
return false
else
return even(x - 1)
end
end
-- (at the repl)
> print(even(10e6 + 1))
false
Testing that way is slow, of course, but if you wanted speed you'd use something more like
function even(x) return x % 2 == 0 end
(and Lua is typically faster than Python, anyway.)
There's also Stackless Python, though I haven't personally done much with it.