Re:Implementing a Type-safe printf in Rust
by AnIdiotOnTheNet on Friday August 14, 2020 @08:22AM
(#24156936)
Zig does it in a similar way, using the compile time type information available to all Zig code, and is in fact implemented in the std library. No magic necessary.
But both fail short to Python/bash.. format strings where you can have "in place" reference to variable which IMHO is much more readable.
Re:Implementing a Type-safe printf in Rust
by ben-schaaf on Friday August 14, 2020 @10:31AM
(#24158406)
I completely agree that string interpolation is often superior to a format string, but it's important to note that they are not equivalent. String interpolation is generally evaluated in-situ and has full access to the local scope. Format strings on the other hand can be passed around and manipulated (even at compile-time) and can only ever access the data they're formatted with. strftime and strptime are a good example of a format string usage that can't be replaced by string interpolation in python.
D also has the capability of implementing string interpolation using mixins - though the resulting code isn't quite as neat.
Re:Implementing a Type-safe printf in Rust
by WalterBright on Friday August 14, 2020 @03:54PM
(#24162486)
I did write a proposal for "in place" reference (i.e. string interpolation) but could not reach consensus with the D community for it.
Re:Implementing a Type-safe printf in Rust
by CyberDildonics on Friday August 14, 2020 @01:16PM
(#24160539)
Formatting text output is not often a problem in the larger scope of a program, but having performance bottlenecks can be.
I don't think D's writefln is getting any special treatment from the compiler. It seems to use D's compile-time features to perform the check.
https://github.com/dlang/phobos/blob/v2.093.0/std/stdio.d#L4...