December 11, 2019 DIP 1027---String Interpolation---Community Review Round 1 | ||||
---|---|---|---|---|
| ||||
This is the feedback thread for the first round of Community Review for DIP 1027, "String Interpolation": https://github.com/dlang/DIPs/blob/148001a963f5d6e090bb6beef5caf9854372d0bc/DIPs/DIP1027.md All review-related feedback on and discussion of the DIP should occur in this thread. The review period will end at 11:59 PM ET on December 25, or when I make a post declaring it complete. At the end of Round 1, if further review is deemed necessary, the DIP will be scheduled for another round of Community Review. Otherwise, it will be queued for the Final Review and Formal Assessment. Anyone intending to post feedback in this thread is expected to be familiar with the reviewer guidelines: https://github.com/dlang/DIPs/blob/master/docs/guidelines-reviewers.md *Please stay on topic!* Thanks in advance to all who participate. |
December 11, 2019 Re: DIP 1027---String Interpolation---Community Review Round 1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | > printf("I ate %s and %d totalling %s fruit.\n", apples, bananas, apples + bananas); Gaah, that should be: printf("I ate %d and %d totalling %d fruit.\n", apples, bananas, apples + bananas); |
December 11, 2019 Re: DIP 1027---String Interpolation---Community Review Round 1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | On Wednesday, 11 December 2019 at 09:52:21 UTC, Mike Parker wrote:
> This is the feedback thread for the first round of Community Review for DIP 1027, "String Interpolation":
>
> https://github.com/dlang/DIPs/blob/148001a963f5d6e090bb6beef5caf9854372d0bc/DIPs/DIP1027.md
>
So we cannot have variables named d, s, f, g, x and so on because they are standard format specifiers. What happens with custom format specifiers, any one letter variable cannot be interpolated?
Why reinvent the wheel and not adopt the common wisdom of {var} as in python, c# an even c++ 20?
|
December 11, 2019 Re: DIP 1027---String Interpolation---Community Review Round 1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | On Wednesday, 11 December 2019 at 09:52:21 UTC, Mike Parker wrote:
> This is the feedback thread for the first round of Community Review for DIP 1027, "String Interpolation":
>
> https://github.com/dlang/DIPs/blob/148001a963f5d6e090bb6beef5caf9854372d0bc/DIPs/DIP1027.md
>
> All review-related feedback on and discussion of the DIP should occur in this thread. The review period will end at 11:59 PM ET on December 25, or when I make a post declaring it complete.
>
> At the end of Round 1, if further review is deemed necessary, the DIP will be scheduled for another round of Community Review. Otherwise, it will be queued for the Final Review and Formal Assessment.
>
> Anyone intending to post feedback in this thread is expected to be familiar with the reviewer guidelines:
>
> https://github.com/dlang/DIPs/blob/master/docs/guidelines-reviewers.md
>
> *Please stay on topic!*
>
> Thanks in advance to all who participate.
Why not just split interpolated string into just a tuple of args & strings. For example:
Given: (i"I ate %apples and %bananas totalling %(apples + bananas) fruit.")
Is lowered to a tuple: ("I ate ", apples, " and ", bananas," totalling ", apples + bananas," fruit.")
It seems current version unnecessarily ties to printf formatting syntax, and makes harder for them to be used in custom user code.
Also user still needs call a function to get assembled string which differs from what other languages are doing with interpolated strings.
Best regards,
Alexandru.
|
December 11, 2019 Re: DIP 1027---String Interpolation---Community Review Round 1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rumbu | On Wednesday, 11 December 2019 at 10:48:56 UTC, Rumbu wrote:
> So we cannot have variables named d, s, f, g, x and so on because they are standard format specifiers. What happens with custom format specifiers, any one letter variable cannot be interpolated?
According to proposal you would wrap format specifiers into {}, like i"%{d}bananas"
|
December 11, 2019 Re: DIP 1027---String Interpolation---Community Review Round 1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandru Ermicioi | On Wednesday, 11 December 2019 at 10:57:13 UTC, Alexandru Ermicioi wrote:
> Why not just split interpolated string into just a tuple of args & strings. For example:
> Given: (i"I ate %apples and %bananas totalling %(apples + bananas) fruit.")
> Is lowered to a tuple: ("I ate ", apples, " and ", bananas," totalling ", apples + bananas," fruit.")
That's an option, but one would also need to figure out handling of format specifiers
|
December 11, 2019 Re: DIP 1027---String Interpolation---Community Review Round 1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | On Wednesday, 11 December 2019 at 09:52:21 UTC, Mike Parker wrote:
> This is the feedback thread for the first round of Community Review for DIP 1027, "String Interpolation":
>
> https://github.com/dlang/DIPs/blob/148001a963f5d6e090bb6beef5caf9854372d0bc/DIPs/DIP1027.md
Nice!
I just have a few nitpicks:
- I don't mind the required prefix 'i', but what about q{} strings? I probably want to use interpolation there as well
- I know it is bikeshedding but since string interpolation is 99% syntax, I vote for "either a single $colon for variables or ${expression} for expressions", like literally every other modern language.
Besides that, this is really nice.
|
December 11, 2019 Re: DIP 1027---String Interpolation---Community Review Round 1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandru Ermicioi | On Wednesday, 11 December 2019 at 10:57:13 UTC, Alexandru Ermicioi wrote:
> Why not just split interpolated string into just a tuple of args & strings. For example:
> Given: (i"I ate %apples and %bananas totalling %(apples + bananas) fruit.")
> Is lowered to a tuple: ("I ate ", apples, " and ", bananas," totalling ", apples + bananas," fruit.")
>
> It seems current version unnecessarily ties to printf formatting syntax, and makes harder for them to be used in custom user code.
Agree. Your suggestion is much more in line with metaprogramming and offers the right flexibility.
Although I think you should just use braces.
Also, change the prefix to "f", so that is is similar to other languages like Python.
So you could get:
log(f"I have {dec(3,2)}{account.total} USD in my pocket")
Becomes
log("I have ", dec(3,2), account.total," USD in my pocket")
That way people can use modern custom formatters if the called function knows how to deal with it.
printf is archaic and hardcoding it into the language just makes the language stuck.
|
December 11, 2019 Re: DIP 1027---String Interpolation---Community Review Round 1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to MrSmith | On Wednesday, 11 December 2019 at 11:00:12 UTC, MrSmith wrote:
> On Wednesday, 11 December 2019 at 10:48:56 UTC, Rumbu wrote:
>> So we cannot have variables named d, s, f, g, x and so on because they are standard format specifiers. What happens with custom format specifiers, any one letter variable cannot be interpolated?
>
> According to proposal you would wrap format specifiers into {}, like i"%{d}bananas"
Nope, that means "use %d format specifier to print number of bananas". According to the DIP, this is invalid:
string what = "bread";
int d = 10;
writefln(i"making %what using %d ingredients");
|
December 11, 2019 Re: DIP 1027---String Interpolation---Community Review Round 1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ola Fosheim Grøstad | On Wednesday, 11 December 2019 at 11:21:08 UTC, Ola Fosheim Grøstad wrote:
> log(f"I have {dec(3,2)}{account.total} USD in my pocket")
>
> Becomes
> log("I have ", dec(3,2), account.total," USD in my pocket")
Actually, make that a tuple, but add proper tuples first. So that you can write
log("Vector {vec_formatter(3,2)}{myvec} is ready.", log_channel)
and it becomes
log (〈"Vector ", vec_formatter(3,2), myvec, " is ready."〉, log_channel )
Where «〈» and «〉» signifies the language-builtin tuple.
|
Copyright © 1999-2021 by the D Language Foundation