-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Design idea: string interpolation #2005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I would like to give this a go. |
Javascript have pretty basic, but easy to understand and use string interpolation(template strings): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals . C# syntax, while being more complex(it incorporates option to specify data formats) is also worth considering in my opinion: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated . |
Yes, I am thinking that maybe I don't know which discord channel we can use for interpolated strings yet, but feel free to share ideas in this issue, I read it regularly. |
We might end up needing to support C++20 std::formatter, so it is possible that our hands are tied as far as number formatting goes. On the upside, the C++20 formatting spec is pretty non-controversial, a lot like Python for instance. |
I don't think that we are constrained by std::formatter syntax in designing string interpolation, but I agree that it is a good idea to get some inspiration from it. Format in interpolation could be specified like this: |
We might be if we want to support formatting of C++ types, see chrono for instance: https://en.cppreference.com/w/cpp/chrono/local_t/formatter (Constrained in the sense that we can do a rewrite to what C++ formatter expects.) |
I was going through wikipedia and found this groovy feature interesting:
It would be good if we can compute the value in the string literal itself. we can fine tune in this way for carbon:
|
Carbon appears to be using
|
We now have a channel on Discord, feel free to share your thoughts here: https://discord.com/channels/655572317891461132/1009125434929201172 |
That Groovy example talks about developers in sexist and ageist terms, and we don't do that here. I know it's copied verbatim from Wikipedia, but that kind of language can still be hurtful when it's inside quotation marks. I've replaced it with a more innocuous example in the comments above (and also fixed the formatting, because the |
@torlarse The link works fine for me. It's #string-interpolation on Discord. Note, if there are any Discord-specific followups, please use a separate discussion to let this issue stay focused. |
This comment was marked as off-topic.
This comment was marked as off-topic.
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the |
Per discussion on #1811, there's interest in string interpolation but it's not an area that's been closely examined. This is an area where a proposal would be helpful.
https://en.wikipedia.org/wiki/String_interpolation gives some information and provides some cross-language examples which may be helpful for proposal background and thinking about options. It's important to consider the syntax that multiple languages are looking at.
In Rust, I think https://www.rustnote.com/blog/format_strings.html and rust-lang/rfcs#2795 may provide some interesting ideas and alternatives to think about. Note though that while
Print
is using meta-programming in Rust, the leads have expressed interest in exploring non-meta-programming-based solutions first.As a possible data source, it may be worth poking at a few sourcegraph searches (such as this one) to see what developers are doing today.
The text was updated successfully, but these errors were encountered: