Feature request: supplement by-name parameter syntax with "lazy" keyword

Semantically it is a val in that (1) it requires storage for its contents, and (2) it doesn’t change.

Semantically it is lazy in that it isn’t computed until it’s needed.

Memoization of parameterless* immutable/pure defs is maybe semantically equivalent, but why explain a simple two-part concept with four concepts, one of which (memoization) is not exactly simple, and which doesn’t tell the entire story unless you think carefully about implementation?

(* They’re generally not actually parameterless unless they’re useless. The parameters are just passed implicitly e.g. by being part of the object upon which the def is defined. So I don’t know that this concept is simple either.)

4 Likes