The state of string interpolation
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Dec 7 20:59:51 UTC 2018
On Fri, Dec 07, 2018 at 03:13:09PM -0500, Steven Schveighoffer via Digitalmars-d wrote:
> My vision of formatted would be simply a pairing of a format specifier
> with a value. It would be up to the function to interpret that (i.e.
> text, or inlineformat or whatever you like).
> But the point is you are coupling the format with the value in the
> same place. Which is the idea behind the "named parameters" that you
> I don't want the language to do any sort of formatting at all. That's
> a library feature. We just need the interpolation feature to give us a
> nicer way to call it.
I see. So that means what we really want is for the language to
translate interpolated strings into tuples that can then be processed by
library code. In other words, it's not really an interpolated string
anymore, it's a kind of "tuple literal" with convenient syntax. It has
general applicability, and can be used for all sorts of interesting
things beyond just interpolated strings. Like your database query
example. In fact, it can even form the basis for implementing my named
parameters idea. Once we have it in tuple form, it can be used for all
sorts of things. (Which makes me wonder if we can even make it a
replacement for std.meta.AliasSeq ...) It would be an enabler of cool
new D idioms, rather than mere syntactic sugar for a "niche" use case.
It also has limited surface area for troublesome / unwanted
interactions. Implementing the scope-as-template-argument idea I
proposed would be a lot more dangerous, because it opens up the
possibility of innocent-looking function calls to access and modify
local variables that are not explicitly passed to it, thus breaking
function encapsulation in a pretty evil way. Standardizing the syntax
in the language, where any accessed local symbols are clearly obvious in
the source representation, eliminates this possibility.
I think we need to sell it to W&A from this angle. :-D This is a lot
more convincing than "PHP-style interpolated strings would be nice, can
we haz it plz, kthxbye".
This is not a sentence.
More information about the Digitalmars-d