Strings and things
Remi Forax
forax at univ-mlv.fr
Fri Sep 17 17:52:08 UTC 2021
----- Original Message -----
> From: "cay horstmann" <cay.horstmann at gmail.com>
> To: "amber-dev" <amber-dev at openjdk.java.net>
> Sent: Vendredi 17 Septembre 2021 19:05:55
> Subject: Re: Strings and things
Hi Cay,
> I am happy with the general direction.
so am i :)
>
> I didn't understand the following sentence: "The only case handled by
> most other languages that support string interpolation is the simplest
> one -- uninterpreted concatenation."
>
> In JavaScript, a tagged template literal does what I understand a
> TemplatePolicy instance to do. In Scala, so does a StringContext. Both
> mechanisms can return instances of arbitrary types, combining the
> fragments and interpolated values as they see fit.
yes, Tagir said the same thing, we have to rework that part to fix that blunder.
> Actually, both do it a tiny bit more nicely, because instead of a templateString one
> gets an array of fragments.
Providing an array of strings is not a good idea mainly because it goes against the lazy evaluation of the parameters, something Brian explained we want to explore.
By example, one of the killer example is to use the String Templating to implement a Logger,
something like
Log."something has gone wrong \(exception)";
(notice, you do not have to get a Logger, store it in a static final, etc, because part of the evaluation of the template will be done once, so the policy can do it for you, that part will not be evaluated several times)
Here, if toString() is called on the exception, you will compute a lot of things to later discover that the underlying Logger may not be enabled,
so it's better to let the policy decide if toString() should be called or not.
Also, receiving the arguments as String has the following issues
- toString() may do a side effect (oops)
- the policy may want to call another method than toString(), by example toJSON() if you have nested JSON objects
>
> Cheers,
>
> Cay
regards,
Rémi
>
> On 16/09/2021 16:28, Jim Laskey wrote:
>> Dear amber-dev,
>>
>> Over on amber-spec-experts, I’ve posted a proposal for “string templates”. I
>> hope people are as excited about this feature as we expect they will be.
>>
>> As a brief reminder, the amber-dev list is not, in general, for language
>> design discussions; this list is primarily for discussion of implementation,
>> bug repoorts, experience reports, etc. We should let the experts do their
>> job without having to follow parallel discussions on multiple lists.
>>
>> If people want to post brief, reasoned feedback on the approach,
>> applicability, or usefulness (but *NOT* the syntax) of the proposal here,
>> that would be fine. Please, let’s keep it constructive.
>>
>> Cheers,
>>
>> -- Jim
>>
>>
>
> --
>
> Cay S. Horstmann | http://horstmann.com | mailto:cay at horstmann.com
More information about the amber-dev
mailing list