News for hackers. Stuff that matters.
Re:Tree Calculus by smsm42 on Tuesday December 10, 2024 @09:07PM (#42383950)
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))
Re:Tree Calculus by chriswarbo on Wednesday December 11, 2024 @07:41AM (#42387159)
Yes, 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)`!