Formalizing f-strings
Formalizing f-strings
Posted Jan 11, 2023 8:24 UTC (Wed) by SLi (subscriber, #53131)Parent article: Formalizing f-strings
It's not. It's because we have separate opening and closing parentheses.
I'm not sure how seriously I'm proposing this, but separate opening and closing quotes exist. Perhaps Python should support them.
Posted Jan 11, 2023 9:11 UTC (Wed)
by dtlin (subscriber, #36537)
[Link] (3 responses)
In Perl, q(...)/q<...>/q[...]/q{...} can be used instead of '...', and qq(...)/qq<...>/qq[...]/qq{...} can be used instead of "...". I don't think this approach would be accepted in Python, though.
Posted Jan 11, 2023 18:56 UTC (Wed)
by mbunkus (subscriber, #87248)
[Link]
my $s = qq|This is "nice", I guess, and $this_var will be interpolated!|;
Even C++ has raw strings with custom delimiters now: R"delimiter( raw_characters )delimiter", e.g.
auto s = R"!(This is "nice", I guess!)!";
Posted Jan 12, 2023 2:39 UTC (Thu)
by NYKevin (subscriber, #129325)
[Link] (1 responses)
(On top of that, Python has, perhaps surprisingly, inherited the "consecutive " "string " "literal " "concatenation" behavior of C, so you can just use two separate string literals if absolutely necessary, and the compiler will concatenate them for you, as if you had written a single string literal. Of course, Python also has peephole optimization and basic constant folding, so this is arguably unnecessary - you could just use plus to concatenate.)
Posted Jan 12, 2023 6:37 UTC (Thu)
by SLi (subscriber, #53131)
[Link]
When I think about it, it just seems kind of nonsensical to use the same thing to start and end something.
Posted Jan 11, 2023 19:00 UTC (Wed)
by pavon (guest, #142617)
[Link] (4 responses)
Posted Jan 11, 2023 20:18 UTC (Wed)
by dtlin (subscriber, #36537)
[Link] (3 responses)
Whose left/right quote marks? The French-style guillemets «...» are more visually distinct than either the English-style “...” and less confusable with other punctuation symbols than the German-style „...“.
If those don't stand out enough, there are many CJK brackets to choose from: 《...》, 「...」, 『...』, 【...】, and more.
Of course, I'm not being entirely serious here, but for comparison, Raku allows for all of those quotes, and then some.
Posted Jan 11, 2023 21:17 UTC (Wed)
by mathstuf (subscriber, #69389)
[Link]
https://jakubmarian.com/map-of-quotation-marks-in-europea...
Posted Jan 12, 2023 2:33 UTC (Thu)
by stephen.pollei (subscriber, #125364)
[Link]
Posted Jan 12, 2023 11:00 UTC (Thu)
by shiar (subscriber, #67206)
[Link]
Formalizing f-strings
In Ruby, %q(...)/%q<...>/%q[...]/%q{...} can be used instead of '...', and %Q(...)/%Q<...>/%Q[...]/%Q{...} can be used instead of "...".
(They both allow for other delimiters as well, but then open and close are the same character.)
Formalizing f-strings
Formalizing f-strings
Formalizing f-strings
Formalizing f-strings
Formalizing f-strings
Formalizing f-strings
Raku
So does (or will) Perl: Formalizing f-strings
use experimental 'extra_paired_delimiters'
in v5.36.