4 ms·
Yes, the two are not identical - in the former, increase is not the part of the closure, in the latter it is. Test: increase = True adjust1 = (lambda x:
by smsm42 2y ago
Yes, the two are not identical - in the former, increase is not the part of the closure, in the latter it is.
Test:
increase = True
adjust1 = (lambda x: x + 1) if increase else (lambda x: x - 1)
adjust2 = lambda x: x + 1 if increase else x - 1
print(adjust1(42))
print(adjust2(42))
increase = False
print(adjust1(42))
print(adjust2(42))
- chriswarbo 2y agoYes, my argument relies on immutability of all values (including `increase`). Also, under lazy evaluation we can call `adjust2` immediately, since we know it's a `lambda`; yet attempting to call `adjust1` will force evaluation of `increase`; not good if `increase = provable(collatz_conjecture)`!