String Interpolation Compare - DIP1027 and YAIDIP

Walter Bright newshound2 at digitalmars.com
Sat Oct 21 03:59:22 UTC 2023


On 10/20/2023 8:51 PM, Steven Schveighoffer wrote:
> YAIDIP:
> 
> ```d
> i"axy:  $a{03} $x{e} $y{20.10}"
> ```

You and I must be reading a different version of 
https://github.com/John-Colvin/YAIDIP

May I quote:

"There is no need for defining, implementing, and memorizing a sui generis 
mini-language of encoded format specifiers --- all formatting can be done with D 
language expressions. Continuing the example, the library can just as easily 
define parameterized formatting for floating-point numbers, such as width, 
precision, and scientific notation:"

```
void fun(double x) {
     writeln(i"$x can be written as $scientific$x or $(fixed(20, 10))$x.");
     // Lowering: --->
     // writeln(.object.imported!"core.interpolation".InterpolationHeader!("", 
"x", " can be written as ", scientific, "", x, " or ", fixed(20, 10), "", x, ".")(),
     //     x, " can be written as ", scientific, "", x, " or ", fixed(20, 10), 
"", x, ".");
}
```


More information about the Digitalmars-d mailing list