6 ms·
> In my very biased and unlearned view the simplest readable versions are Javascript and Lua. The Python version listed there doesn't actually meet the requir
by portLAN 19y ago
> In my very biased and unlearned view the simplest readable versions are Javascript and Lua.
The Python version listed there doesn't actually meet the requirement (it doesn't return a function, it returns a class instance, and it keeps modifying n every time it's called).
Corrected version:
def foo(n): return lambda (i): n+i
Which is essentially identical to the Common Lisp version.
- earthboundkid 19y agoIf it's supposed to be an accumulator, I take it they want the value of n to be changed each time. I'd do: def acc(n): while True: n += yield n
- portLAN 19y agoBut emphasizing correctness makes my one-liner not work! And reading the original I can see this whole issue was already covered! BTW, generators are non-callable.