The state of string interpolation
o
o at o.o
Thu Dec 6 22:03:55 UTC 2018
On Thursday, 6 December 2018 at 16:19:12 UTC, Steven
Schveighoffer wrote:
> [...]
> Most languages I know of create a string with toString-ing the
> interpolations.
>
> [...]
>
> The mixin/library solution is much less approachable. What's
> awesome about the language solution is that it just works
> without much extra understanding and verbosity, and need for
> using mixins. mixins are cool, but are best tucked away behind
> templates or generative functions. They shouldn't seen much in
> user code. Saying we should use a library solution for this is
> like saying we can replace foreach usage with a library foreach
> that lowers to some for-loop and explicit delegates (or maybe a
> mixin?). Yes, it could be done. No, it shouldn't be done. This
> is one of those types of syntax sugar that should not be
> ignored.
Well said.
I agree that lowering to a tuple opens up some cool
possibilities, but what about the times when it is desired to
just use string interpolation as just a plain string?
For example, if `i"a is ${a}."` is equivalent to 'tuple("a is ",
a, ".")', then if you want to use the interpolated string as a
string, you would have to do something like `text(i"a is
${a}.")`. If this is the case, how much better is this over a
library implementation, which would look like this: `interp!"a is
${a}."`?
I am definitely not saying that a library solution is a better
idea. I personally think that this only makes sense as a language
feature. But I just think it would be best if `i"a is ${a}"` is
more or less equivalent to `"a is "~a.to!string~"."`.
As you said, string interpolation is just (very nice) syntactic
sugar over concatenation, so I think we should make this sugar as
sweet as possible.
More information about the Digitalmars-d
mailing list