The state of string interpolation
schveiguy at gmail.com
Thu Dec 6 20:08:20 UTC 2018
On 12/6/18 2:52 PM, Adam D. Ruppe wrote:
> Passing the actual variable as a CT arg is doable.. but only if there IS
> an actual variable.
> i"hi $(name)"; // could pass T!("hi ", name)
> i"hi $(a+b)"; // error: cannot read variables at compile time
Yeah, I know. I was hoping we could bend the rules a bit in this case.
Since an interpolation would be a different kind of alias (with special
traits attached), it could have its own allowances that normally don't
happen. Make it like a lazy alias ;)
> Now, maybe we don't want to support $(a+b)... but I think people would
> miss it. How many times in PHP or Ruby or whatever do we say:
We have to support it. Of course, it would be supported for the runtime
mechanism (where you lose the compile-time introspection). But it would
be cool to have the compile-time traits allowed as well.
> (BTW it is interesting passing an int to a function with an interpolated
> string. but since it doesn't automatically convert and just does a
> tuple.. you can totally do that.)
This is why I think the idea is different and vastly superior to most
other language string interpolation mechanisms.
More information about the Digitalmars-d