String Interpolation
Arafel
er.krali at gmail.com
Mon Oct 23 07:48:28 UTC 2023
On 22/10/23 23:55, Steven Schveighoffer wrote:
> FWIW, that is something Adam opposed, but I insisted on. I did not think
> a String Interpolation DIP would be viable without it.
That's why I mentioned that he was a co-author, I guessed something like
that might have happened. Still, he was asking for evidence when he had
put his name to that, so at the very least he should be aware that it's
a very common view.
FWIW, I fully agree with you that the primary objective of string
interpolation should be building strings. I've been trying to find
references, and everything I found online just _assumes_ that this is
the case.
Of course if you can **also** do something else with that it's even cooler.
>
> I still feel like one should be able to use an interpolation tuple as a
> string, but it's really hard to come up with a design that doesn't feel
> like a complete hack.
The problem is that it's inherently a high level feature. There's a
reason why it first appeared and is even now still mostly used in
interpreted languages.
Now, you want to embed it into the core of a language that tries to be
minimalistic, so I understand that there are parts, for instance
formatting numeric expressions, that doesn't really fit there.
But then you / the D leadership / the D Community should make a decision
if we are to ever have this feature: either embed it into the language
and bite the bullet, reusing for instance pragma msg's formatting
routine, or extend the language so it can be implemented as a library.
I actually prefer the latter, and adding a shorthand for mixins might be
a good solution, even if I also understand the preference for having
mixins not too easy to use and clearly marked in the source code. Well,
you can't have all, and as usual there are trade-offs.
> It's indeed much much simpler to just push that requirement to build a
> string if desired on the user.
Also, you (Adam, Walter, even you) are usually arguing form a library
writer's perspective.
On the other hand, me, as a user of other people's libraries, will often
need to deal with places that I have no control over, and that only
expect strings, or even C interfaces that want a char*.
Sure, I can use `text` all the time, but this kind of removes most of
the usefulness of the feature.
So I think any such feature needs to be exclusively, or at least mostly,
a caller thing.
> -Steve
>
More information about the Digitalmars-d
mailing list