lazy evaluation of string templates
See original GitHub issue[@gavinking] The spec promises that string templates are lazily evaluated, but dodges the question of how exactly that works. This is actually a bit of a tricky problem if we want to continue to support the syntax:
String s = "Hello, " name "!";
Let me run through several options:
- Don’t support the above syntax. A string template is a
StringTemplate
. If you want to get aString
out of it, you have to callstring
explicitly. - A string template is just a
String
. To re-evaluate it, you callinterpolate()
to get a newString
. This doesn’t work out if we continue to lowerString
tojava.lang.String
, but if we decide to change our minds about that (it is on the cards), then it could work. - Make string interpolation eager all the time. To get lazy evaluation you write
() "Hello, " name "!"
, or use some other weird syntax to get aString()
instead of aString
.
Thoughts?
[Migrated from ceylon/ceylon-spec#345]
Issue Analytics
- State:
- Created 11 years ago
- Comments:35 (3 by maintainers)
Top Results From Across the Web
Lazy evaluating string literals in JavaScript [duplicate]
I have a case where a template literal can resolve a variable immediately, but the next in order doesn't. I have to wait...
Read more >[antlr-interest] Example of lazy evaluation in string templates ?
Ter On Mar 19, 2009, at 4:16 AM, bernard at ballesta.fr wrote: > Hi, > > Does someone know of a real example...
Read more >Make string template evaluation lazy · Issue #1791 · babel/babel ...
Babel (5.0.4) expands string template in place using concatenation operator (+). The problem is this inhibits passing templates as function arguments (refer ...
Read more >Except that f-strings are not lazy evaluated so you cannot ...
I think you're conflating format strings with the lazy evaluation associated with logging. I am, however, in complete agreement that logging should adopt...
Read more >how to delay interpolation of template strings? - ESDiscuss.org
I think you would need to evaluate the template string inline in order to interpolate its result ... OR. you just go for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
These days, we can just write
(name) => "Hello, " name "!"
and that’s fine. Closing this very ancient and obsolete issue.@xkr47 yeah, sure, I copy/pasted from the very ancient issue description.