String Interpolation

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Oct 25 11:29:14 UTC 2023


On Wednesday, October 25, 2023 2:00:38 AM MDT Arafel via Digitalmars-d wrote:
> On 25/10/23 8:49, Walter Bright wrote:
> > Thank you. The trouble is with the mixin. It can't be dispensed with.
>
> Well, I know you want to make mixins clearly identifiable, but I would
> suggest some easy sintax for string mixins generated by a template.
>
> For instance, using `!!` (I think it's an unused token):
>
> ```d
> foo!!(a, 42)
> ```
>
> would be literally just another way of writing:
>
> ```d
> mixin(foo!(a,42))
> ```
>
> and thus anybody could implement:
>
> ```d
> i!!"Helo ${name}"
> ```
>
> as a library solution, or even use the existing ones.
>
> You could create mixins that are tighly coupled to the called function,
> or generic ones... it would be the most flexible solution.

IMHO, mixins should be explicit, obvious, and greppable, and adding a
separate syntax for them which tries to hide them is going to make the
language worse. However a string is generated, if the programmer wants to
turn it into code, they should just use mixin, and if it's ugly, it's ugly,
but at least it's clear what's going on.

- Jonathan M Davis





More information about the Digitalmars-d mailing list