-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attribute lazy initialization #438
Comments
Or even shorter if it is possible to do something like this:
"?=" will cause that createFoo() is called on first usage of foo. |
The non-variable version is bad cuz you're accessing a value before it's been initialized.
would be bad because between
|
+1 for this syntax:
|
So, @matejonnet has a point here. The simplest I was able to get was the following:
which sorta took me by surprise. It's a bit better than what @matejonnet writes above, but it's still unacceptably verbose. The big problem here is that, ages ago, @FroMage asked me to change the type of assignment expressions like
Which I think would be acceptable, no? @FroMage WDYT, can we change this back? |
@luolong The following would certainly work:
where |
I'd like a way to define lazy memoised attributes, I've already made that clear. Perhaps I think that Integer computeVal() => ... ;
cached shared Integer val => computeVal(); I mean, if we introduce |
|
FTR, I'm not advocating I'm also not against eventually introducing a Fantom-style |
Fair enough, but changing the type of |
Only when:
|
Sure. |
Lazy actually typically means memoized. A while back I had proposed that Lazy foo = {compute()}; foo.eval On Thursday, January 3, 2013, Stéphane Épardaud wrote:
|
I have made that change to the type of
Now reducing issue priority and shifting out of Ceylon 1.0. We can re-discuss this stuff for a future version. |
P.S. the backend needs to be fixed to support this change to the semantics of a nested assignment operator. |
I see this has been suggested for 1.5 but I've already encountered several times wanting something like this. Maybe we could move it a bit forward to 1.3? It doesn't seem too hard too implement but can still quite useful. Of course Gavin's 2-liner is not too bad, but nothing can beat:
|
I also vote for |
Why not "shared lazy Integer val => computeVal();"?
|
@kelvio Ok clarification; It is especially the syntax that I am happy with. Regarding the word to use for enabling it should of course make it clear that |
Got it. 2015-11-02 10:24 GMT-02:00 Jonas Berlin [email protected]:
Atenciosamente, Kelvio Matias Santos Silva. |
I like |
+1 on |
But "once" is an adverb, and you decided to use adjectives for annotations, as stated in the faq:
|
Somehow I feel that |
maybe we should borrow from the functional languages terminology and call it |
so the example would read like this: shared memoized Integer val => computeVal(); |
+1 on
While using a verb in a Ceylon annotation seems a big no-no, I think people would accomodate the use of an adverb. |
👍 for |
I vote for cached. |
I kind of disagree with |
Just wished for this again, so bumping to add my support for |
Folks this issue migrated to eclipse-archived/ceylon#3544. |
Looking for a shorter way to initialize an object attribute on a first use,
and ability to use immutable attribute instead of variable
I would like to write this as:
The text was updated successfully, but these errors were encountered: