The state of string interpolation
Mike Franklin
slavo5150 at yahoo.com
Fri Dec 7 00:43:43 UTC 2018
On Thursday, 6 December 2018 at 22:04:13 UTC, Steven
Schveighoffer wrote:
> It's really not what's enabled (clearly, things can still be
> used without string interpolation, and we can use mixins to
> simulate close to what we would want).
>
> It's how one writes and reads code. The efficiency and elegance
> is not to be ignored.
[..]
Of course, you are right, and that's what I was trying to say.
"What language feature do we need, or limitation removed, that
gets us what we want: the ability to implement interpolated
strings and potentially other features in the library without too
much compromise on the efficiency, elegance, and expressiveness
you would get if you implemented it in the language, and without
turning D into a DSL". That probably doesn't do it justice
either, but I hope you get the idea and we're on more-or-less the
same page.
Jacob mentioned AST macros (I knew that was coming, and even had
a note in my first draft say "Sorry, Jacob, except for AST
macros", but I deleted it :D ). But Jacob is on to something.
We already pass around symbols with `alias`. Can that be
extended somehow to pass around expressions too (i.e. expressions
as rvalues)? That would probably help address the issue of
printing assert expressions as well
(https://github.com/dlang/dmd/pull/8517)
Zodian mentioned eponymous mixin template at
https://forum.dlang.org/post/tnebtoplmhtpabnlvydw@forum.dlang.org
H. S. Teoh mentioned using mixins as expressions at
https://forum.dlang.org/post/mailman.5553.1544132869.29801.digitalmars-d@puremagic.com
As for myself, I don't see much value in forcing users to add
`mixin` at the site of a mixin template instantiation, but
there's a lot I don't see, so I may just be missing something.
```
import std.stdio;
mixin template Foo(T)
{
T x = 5;
}
extern(C) void main()
{
// Why do we need `mixin` here?
// Why can't we just write `Foo!int;`?
// It's already yelling at us with a ! operator.
mixin Foo!int;
writeln(x);
}
```
Simen Kjærås mentioned a few things when we were discussing ways
to implement properties in the library at
https://forum.dlang.org/post/jqcqsriizuewdqotbnop@forum.dlang.org
There might be some feature to be added, or limitation removed,
that will permit help both the string interpolation case and the
properties case.
I know I'm just thinking out loud and not contributing much, but
I can't help but feel that there's something common in all these
ideas that just hasn't been identified yet. And no, Jacob, not
AST macros (Actually, that would probably do it, but I think
we've already been there) :D
Mike
More information about the Digitalmars-d
mailing list