Lazy formatting

Steven Schveighoffer schveiguy at
Mon Feb 1 15:34:20 UTC 2021

On 2/1/21 8:31 AM, Kagamin wrote:
>> This is how I would do it:
>> i"Hello, ${var.withFormat!"%45s"} world";
> I have a feeling recent DIPs are too detached from practice. If you read 
> feature requests, people wanted interpolated strings in order to easily 
> construct strings without tinkering. For ease of use. But the DIP's 
> design rationale ended up being "because other languages have this". As 
> design thus loses direction you end up designing an abstract silver 
> bullet of interpolated strings without regard for practical needs. But 
> we already have plenty of ways to tinker with string formatting. Who 
> asked for one more way to do it? Almost all uses of interpolated strings 
> are trivial ones i"I have ${n} apples".

I'm not sure how you read this as "cuz other langs do it":

But in any case, the `withFormat` thing has nothing to do with the 
referenced DIP. That's why we're in a separate thread here.

I have wanted in the past to just have a construct that says "format 
this value", but not have to decide where it goes. In other words, a 
lazy formatting.

All of std.format expects a *destination* to put formatted data. I want 
the *source* to just be formatted data.

It's actually a lower level abstraction than what is already in 
std.format, which could be built upon such a thing. Just an idea any way 
(and of course, it's relevant for string interpolation to anyone who 
might want a one-off format difference than the default).


More information about the Digitalmars-d mailing list