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

jmh530 john.michael.hall at gmail.com
Wed Dec 11 14:41:39 UTC 2019

On Wednesday, 11 December 2019 at 11:21:08 UTC, Ola Fosheim 
Grøstad wrote:
> [snip]
> Also, change the prefix to "f", so  that is is similar to other 
> languages like Python.
> [snip]

Python has f interpolation that looks like
print(f'Hello {name}! This is {program}')
but it also has % formatting that looks like
print(‘Hello %(name)s! This is %(program)s.’%(name,program))
This %(name) is probably the closest that compares to this DIP, 
but it seems like the Python 3.6 string interpolation was meant 
to replace that.

Scala also has f interpolation, but they also have s and raw 
The f is like
println(f"$name%s is $height%2.2f meters tall")
the s is like
println(s"Hello, $name")
and the raw is like
The raw strings would correspond to D's r strings.

However, from that string interpolation page from wikipedia, I'm 
not seeing a lot of other examples of languages that use the f. 
Many of the languages on there do not require a prefix, though it 
seems to be mostly dynamic languages. It looks to me like most of 
the languages from the Visual Basic/C# microsoft line of things 
use a $ interpolation as in
Console.WriteLine($"Hello, {name}")

It looks most common to use $var, ${var}, ${expression}, or a 
little more rarely just {var}.

I like Scala's syntax, but you could probably bring together the 
f and s strings by just providing a default if there is no format 

More information about the Digitalmars-d mailing list