The state of string interpolation

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Dec 8 00:21:13 UTC 2018


On Fri, Dec 07, 2018 at 11:46:45PM +0000, o via Digitalmars-d wrote:
> On Friday, 7 December 2018 at 20:59:51 UTC, H. S. Teoh wrote:
> > 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".
> > 
> > 
> > T
> 
> Also, see Andrei's comment:
> https://github.com/dlang/dmd/pull/7988#issuecomment-375760720

I think the DIP must take Andrei's comment into account. I.e., we should
create possible library solutions, and discuss the pros and cons, esp.
to enumerate the ways in which a language-backed implementation would be
superior.

A few specific points that come to mind:

- Mixins essentially grant the callee unrestricted access to the
  caller's scope.  This leads to the possibility of surprising behaviour
  (e.g., what looks like an innocent function call or interpolated
  literal causes local variables to change, that aren't directly passed
  to the function).  Mixins are also a last-resort feature that we
  generally don't prefer if less intrusive means are available to
  achieve the desired effect.

- Having the language segment the literal into a tuple of strings and
  aliases (as opposed to outright string interpolation) has
  applicability beyond mere string interpolations. Steven's database
  idea would be great to use to strengthen this point.  We could also
  think up some more advanced examples that embed, e.g., functions
  (rather than merely variables) that the callee can use to transform
  the input string segments in interesting ways that go far beyond what
  mere string interpolation does.  Code generation techniques come to
  mind (e.g., specify a function that generates a loop around a block of
  code specified in string form).

- Andrei's last point about needing to import std.typecons is false.
  Built-in tuples (aka AliasSeq) does not depend on
  std.typecons.AliasSeq; it's a compiler construct that AliasSeq merely
  gives a useful name for.  What we're really doing is turning an i"..."
  literal into a *template argument list*.

Andrei also mentioned nicer mixin syntaxes, which was also discussed in
this thread.  Our discussions should be rephrased and summarized in a
way that directly answers Andrei's points.


T

-- 
People tell me I'm stubborn, but I refuse to accept it!


More information about the Digitalmars-d mailing list