DIP 1027--String Interpolation--Final Review Discussion Thread
Steven Schveighoffer
schveiguy at gmail.com
Sun Feb 2 18:46:36 UTC 2020
On 2/2/20 9:29 AM, Adam D. Ruppe wrote:
> On Sunday, 2 February 2020 at 14:20:16 UTC, Timon Gehr wrote:
>> This is a use case for `alias this`, the language just has to support it.
>
> Indeed.
>
> So is
>
> string s = i"";
>
> so idk which one we'd use (unless the language gets multiple alias this
> lol).
>
> But regardless the struct lets us have it all. With alias this it is
> every minor detail. Without it it is a simple method call.
>
> I used to lukewarm support this DIP, but since the struct is so much
> better, superior in almost every objective measure, I now think we
> should vote it down unless it changes.
The problem I have with the struct mechanism is that it enforces the
parameters are all non-reffable data.
e.g., this should work with the DIP as proposed:
int apples;
int bananas;
readf(i"I have $apples apples and $bananas bananas");
I don't know how you do that with a struct as the result of the
interpolated string without knowing how the parameters will be used.
Or this:
struct S {}
foo!(i"I'm passing $S as an alias/type, with some formatting data around
it");
Other than that, I like the idea of the struct for the purposes of
overloading. I still would like the format string to be a custom type
that devolves to string. I also liked the straight conversion to a tuple
where every other parameter was a string (i.e. Marler's implementation).
The biggest thing that the DIP has going for it is that there are lots
of functions which have a format string + args, due to the way D/C does
varargs, and this will be a drop-in call without having to change any
code or add special overloads. The whole printf thing is meh to me, I
don't use it and don't care to use it with this mechanism anyway (writef
is a different story).
And Walter:
C functions aren't overloadable?
This works just fine:
---------
import core.stdc.stdio : printf;
void printf(int x) { printf("%d", x); }
void main()
{
printf("hello %d\n", 5);
printf(5);
printf("\n");
}
---------
output:
hello 5
5
-Steve
More information about the Digitalmars-d
mailing list