<div dir="ltr"><div class="gmail_default" style="font-family:monospace">I feel like that would be on the logging libraries to provide, not so much the language.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Let's say that your problem (as I understand it) is like this.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">log.debug("metrics = \{this.expensiveComputationThatNormallyWouldntRunUnlessYouActivateDebug()}");</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Sounds to me like the solution is this instead.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">log.debug(() -> 
"metrics = \{this.expensiveComputationThatNormallyWouldntRunUnlessYouActivateDebug()}"

)</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">So, your logging library just needs to add a new overload for a Supplier<StringTemplate>, and then this problem is solved entirely outside of the language. Log4J and friends are pretty good about keeping up with new additions, so it should not take long.<br></div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">
I know it's a little less convenient, but doing it this way helps keep 
out complexity from the feature, and only introduces it where necessary 
(and it's only necessary at use-site).

</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Would this meet your needs?<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 17, 2024 at 11:15 AM Justin Spindler <<a href="mailto:justin.spindler@gmail.com" target="_blank">justin.spindler@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I was toying around with the second preview of StringTemplates and I had a question regarding their design.  I was wondering if it had been considered for the embedded expressions to be evaluated lazily?<div><br></div><div>One of the first use cases that came to mind when I was exploring StringTemplates is logging.  That is an extremely common case where we want to produce a form of interpolated value, and the current syntax generally has the same concerns that a formatted string would, in that the inputs are removed from where they are defined within the message format.  However, if the log message is below the log level threshold you generally don't want to incur the cost of building the message, including evaluating those embedded expressions.  Log libraries typically offer a mechanism to defer evaluation via Suppliers, but that feels like it would be a challenge to use within StringTemplate.</div><div><br></div><div>C# is an example of a language that offers this functionality via FormattableString, which gives a method the ability to choose whether or not to interpret the template or evaluate the expressions.  That allows logging below threshold to be more or less a no-op.</div><div><br></div><div><br></div></div>
</blockquote></div>