The state of string interpolation...one year later

Steven Schveighoffer schveiguy at gmail.com
Mon Mar 18 13:05:37 UTC 2019


On 3/18/19 8:12 AM, Kagamin wrote:
> On Sunday, 17 March 2019 at 18:32:55 UTC, Jonathan Marler wrote:
>>>> foreach (i; 0 .. 10)
>>>> {
>>>>     mixin(interp(`$( i ~ ")" ) entry $(array[i])`));
>>>> }
>>>
>>> That doesn't look nice, does it?
>>
>> Not sure if you realize this but you're criticizing how the library 
>> solution looks, which was one of my main points :)
> 
> I mean $( i ~ ")

Yeah, you could write it I think just like the language solution:

mixin(interp(`$(i)) entry $(array[i])`));

You'd still have to deal with the stray parentheses as a string, but I'm 
sure there are other expressions inside the escapes that are more likely 
to be in the wild which would require a lexer/parser. It may not be a 
full one, though, we don't need to make AST out of it.

> 
>> And it's a contrived example to demonstrate an example that would be 
>> hard for a library to parse.
> 
> It's hard to parse even for a library? That sounds bad. Is it required 
> to be hard to parse?

If you look at the PR that he created, it's super-simple. It uses the 
already existing parser/lexer in the front end.

The point he's making is that we'd have to DUPLICATE that for a library 
solution.

-Steve


More information about the Digitalmars-d mailing list