
[... big snip...] On 22Jan2022 01:41, Chris Angelico <rosuav@gmail.com> wrote:
On Sat, 22 Jan 2022 at 00:56, Joao S. O. Bueno <jsbueno@python.org.br> wrote:
At that point, I argue that despite adding still more things to the syntax, it is one that will spare time in average than the other way around, due to the time people, needing frozensets for the first time in any project, waste looking for a literal syntax for them only to find out there is not any.
Have you any stats on this? There is no literal/display syntax for datetimes, regular expressions, ranges, bytearrays, or a host of other common types. How often do people reach for a literal syntax for those? (I say "literal/display" since, technically, dicts have a display syntax, not a literal, and complex numbers are written as a constant-folded sum, but in practical terms, those count. The other types don't even get that.) If frozensets are so special that they need syntax, why not ranges, which are used far more frequently?
Well, some data. a) if the, for example, f{constant-set-display} syntax is generalisable (notionally, where we generalise it or not), it offers a path to frozen literals for other things via a prefix notation, should be become desirable. b) literal regexps: people use these _all the time_, conceptually. To the latter: Perl has literal regexps, you just write: /regexp-goes-here/ It even has a verbose commentable form of that to aid writing understandable regexps (hahaha!). What, we're not Perl? True, but you see _lots_ of code like this: # apologies if I have the argument order wrong here if re.match('regexp-string', 'target-string'): which effectively relies on the re module's autocaching of regexps to be efficient while skipping the more overt: # top of module foo_re = re.compile('regexp-string'[,options]) .... # in the main code if m := foo_re.match('target-string'): The former is nothing else but a metaphor for a literal regexp. I'm _not_ arguing for regexp literals in Python - IMO they're undesirable, a separate argument. (Note: not "undesired", just undesirable: to be avoided except when they're the right solution.) Cheers, Cameron Simpson <cs@cskk.id.au>