On Wednesday, 19 April 2017 at 12:10:33 UTC, Jonas Drewsen wrote:
On Wednesday, 19 April 2017 at 12:03:47 UTC, Stefan Koch wrote:
On Wednesday, 19 April 2017 at 11:59:51 UTC, Jonas Drewsen
wrote:
What about supporting an optional prefix inside the {} like:
int year = 2017;
format($"The date is {%04d year}");
so if there is a % immediately following the { then the chars
until next whitespace is format specifier. You can of course
leave out the format specifier and it will default to %s.
I really don't see how string interpolation is better then
` "The date is " ~ format("%04d", year)); `
As mentioned before it is only because it is such a common
pattern that it justifies the change. Seems like many other
languages reached that conclusion as well.
Also take a look at a more realistic example with some more
formatting and it will be more obvious (at least to me it is :)
)
"The date is " ~ format("%04d", year)) ~ " and " ~ user ~ "
just logged into " ~ here;
$"The date is {%04d year} and {user} just logged into {here}"
I see.
So you want to build format strings as well.
This is going to be nasty, and likely to complex for a robust
implementation.
Here is what I would support:
String interpolation literals can only be used with strings.
And they need to start with some prefix which is not an operator.
I"The date is %dateString and the time is %timeString"