On 2018 Apr 27 , at 9:05 a, Steven D'Aprano firstname.lastname@example.org wrote:
Actually, I think I can think of a way to make this work, if we're willing to resurrect some old syntax.
On Fri, Apr 27, 2018 at 09:27:34PM +1000, Steven D'Aprano wrote:
I think that this is either a great idea or pointless, depending on what the built-in actually does.
If all it does is literally the debug print function you give:
# "debug print": prints and then returns its argument def dp(obj): print(repr(obj)) return obj
then it is just a trivial helper as you say, and in my opinion too trivial to bother making a builtin.
I changed my mind... let's add this as a builtin, under the name debugprint. It is a completely normal, non-magical function, which takes four (not one) arguments:
def debugprint(obj, lineno=None, module=None, source=None): [magic elided]
Now let's put all the magic into some syntax. I'm going to suggest resurrecting the `` backtick syntax from Python 2. If that's not visually distinct enough, we could double them: ``expression``.
I don't want to hijack the thread on a digression, but instead of bringing `` back for just this one purpose, it could be used as a prefix to define a candidate pool of new keywords.
``debugprint(obj) # instead of ``obj`` meaning debugprint(obj)
Any ``-prefixed word would either be a defined keyword or a syntax error.