On 24/09/2025 11:38, Per-Ake Minborg wrote:
I think the other examples you show (albeit I didn't fully get how they were supposed to work) would have issues regardless of whether there were language or library support for lazy computation

I'd like to amplify this point a little.

Your example shows the use of a singleton -- an object that is constructed once, then stashed in a static final field.

However, the construction of the singleton (getInstance method) depends on a parameter.

This means that, effectively, getInstance will capture whatever parameter value was passed the first time it was constructed.

Now, there might be use cases for this, but such a use case would also not be supported if using Kotlin's lazy, Scala's lazy val, or our LazyConstant API (all of them are equivalent from an expressiveness point of view).

So, your claim that

this may indicate that a keyword or annotation-based solution could be a better fit.
Feels a bit off -- either the example you provided is not what you really had in mind, or, when you say _keyword_ you mean something other than a lazy-like keyword (but as Per explained, while there are some more obscure keywords in other languages that might provide more flexibility, the semantics associated with such keywords feels a bit ad-hoc, and surely not something we would like to permanently bolt onto the language).

Cheers
Maurizio


Reply via email to