Will Bradley writes:

 > C++ has custom literal syntax
 > <https://en.cppreference.com/w/cpp/language/user_literal>. I couldn't find
 > a PEP on the subject— has this been considered and rejected, or is there a
 > reason it's unpopular?

I'm pretty sure there is no PEP on that specifically, and I can't
recall it being proposed.

I don't know about C++-style user literals, but in general Python has
rejected user-defined syntax on the grounds that it makes the language
harder to parse both for the compiler and for human beings.  Python
has a fixed set of operator symbols in any version (operator symbols
have been added in the past and more may be added in the future), with
a standard way of providing semantics for each operator (with a few
exceptions: assignment is name binding, not an operation on objects,
and the semantics can't be changed, 'is' is object identity and can't
be overloaded, and the ternary operator 'x if test else y' can't be
overloaded).  Proposals for user-defined operator symbols as in
Haskell's `` notation or R's %% notation have been outright rejected
on that principle.

There was a proposal to provide literal syntax for physical units like
meters, kilograms, and seconds, along the the SI magnitude prefixes.
I think that got to the "proto-PEP" stage, but it got a lot of weak
opposition for a number of reasons, mostly "Python isn't intended for
creating DSLs and the units module gives the semantics needed via
classes", and petered out without an actual PEP IIRC.

There are frequently proposals to give the Decimal constructor a
literal syntax, always rejected on the grounds that it's not needed
and there hasn't been a really compelling syntax that everybody likes.

There are also frequent proposals to create special string literals,
with occasionals successes like rawstrings (the r"" syntax) and more
recently f-strings.  The most popular is some kind of lookup syntax
with the primary use case being internationalization, which typically
grabs the single underscore as the marker for a localizable string
(it's aliased to the gettext function).  This is annoying and
inconvenient because it conflicts with the common usage of "_" as a
placeholder.  This hasn't yet had a compelling proposal, I think
there's a dormant PEP for "i-strings".

I'm sorry that my memory is not entirely clear, but that gives you
some idea of how such discussions have gone in the past.  The f-string
PEP and the i-string PEP, there's also a PEP for "null coalescing"
operators I believe, would give you some idea of how the core devs
think about these issues.

Perhaps somebody with a better memory can be more precise.  Until
then, this is what I've got. :-)

Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7QO52Y2Z2OPUSDJKXXMAW3QQ7IRTOR5A/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to