Just another example of missing string interpolation

Commander Zot no at no.no
Fri Oct 20 15:29:29 UTC 2023


On Friday, 20 October 2023 at 13:45:40 UTC, Steven Schveighoffer 
wrote:
> On Friday, 20 October 2023 at 07:14:45 UTC, Walter Bright wrote:
>
>> [...]
>
> If this is supposed to be a favorable comparison of 1027, this 
> has failed.
>
> 1027 requires runtime processing of a compile-time format 
> string. It requires that you implement escapes for the %s spec 
> and for literal %, or just know that your domain doesn't have a 
> valid use for %s normally (though this always can be proven to 
> be a mistake by users). It is not friendly to multiple 
> interpolation strings sent to the same function (how does the 
> function know this is a new header?)
>
> YAIDIP or 1036, there is no discarding of the processing the 
> *compiler already did* to parse the format string. Think about 
> that -- with 1027 the compiler parsed the interpolation tuple, 
> and built a puzzle string for you to have to figure out what it 
> did during runtime.
>
> Who cares what the generated tuple looks like? Nobody will see 
> it. Do you care what other lowerings in the compiler look like? 
> Because a lot of times they are god-awful monstrosities that 
> nobody would write themselves. Is that something to object to?
>
> All the proposed solutions, including 1027, can be worked with 
> for most cases. It's just that the code to adapt 1027 to calls 
> except for printf and writef is awful. It doesn't handle other 
> situations at all.
>
> And 1027 still has the problem of matching functions it 
> shouldn't match. Do you recall Adam's example of exception 
> construction?
>
> ```d
> throw new Exception(i"Invalid integer value in $file: $val");
> ```
>
> -Steve

thank you.
i agree, YAIDIP is the best solution so far, but i think we 
should take a step back and think about the real porblem: why 
can't we do it with existing language features, and what would be 
required to simply make ```foo(i!"cool ${var} rox");``` work 
instead. because adding that feature might benefit a lot more use 
cases.


More information about the Digitalmars-d mailing list