DIP 1027---String Interpolation---Community Review Round 1

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Dec 11 11:21:08 UTC 2019


On Wednesday, 11 December 2019 at 10:57:13 UTC, Alexandru 
Ermicioi wrote:
> Why not just split interpolated string into just a tuple of 
> args & strings. For example:
> Given: (i"I ate %apples and %bananas totalling %(apples + 
> bananas) fruit.")
> Is lowered to a tuple: ("I ate ", apples, " and ", bananas," 
> totalling ", apples + bananas," fruit.")
>
> It seems current version unnecessarily ties to printf 
> formatting syntax, and makes harder for them to be used in 
> custom user code.

Agree. Your suggestion is much more in line with metaprogramming 
and offers the right flexibility.

Although I think you should just use braces.

Also, change the prefix to "f", so  that is is similar to other 
languages like Python.

So you could get:

log(f"I have {dec(3,2)}{account.total} USD in my pocket")

Becomes
log("I have ", dec(3,2), account.total," USD in my pocket")

That way people can use modern custom formatters if the called 
function knows how to deal with it.


printf is archaic and hardcoding it into the language just makes 
the language stuck.




More information about the Digitalmars-d mailing list