Builtins.lazy for lazy arguments

Indeed. But there are drawbacks to this.

  1. This would not be backwards compatible.
  2. Unnecessary inconvenience passing callables as arguments, which is a very common occurrence. A lot of code would need to adapt to facilitate lambda lazy evaluation paradigm.
  3. Performance. E.g. lambda check is expensive: callable(x) and x.__name__ == '<lambda>. It also needs try-except as not all callables have __name__. Creation of lambda is also more expensive. While callable check on its own is too general - unsuited for the purpose.
  4. Value binding at evaluation is not a good property for this application. E.g. lambda: a + 2 versus lazy(opr.add, a, 2). The latter is contained within itself, while the former can not be used in places where a changes value, e.g. loop. This is quite a major inconvenience which subtracts a lot of value from this.
1 Like