[Python-ideas] Yet another idea for assignment expressions

Ken Hilton kenlhilton at gmail.com
Wed May 2 02:21:19 EDT 2018


Hi all,

I've been following the discussion of assignment expressions and what the
syntax for them should be for awhile. The ones that seem to crop up most
are the original spelling, :=, the "as" keyword (and variants including
it), and the recently "local" pseudo-function idea.

I have another idea for a spelling of assignment expressions, mostly
inspired by real sentence structure. In a review I was writing recently, I
referred to CGI, Computer Generated Imagery. As a way of introducing the
full term and its abbreviation, I said "Computer Generated Imagery (CGI)".
That got me thinking: why not have something similar in Python? Obviously
simple parentheses ("expr(name)") definitely wouldn't work, that's a
function call. Similarly, brackets ("expr[name]") would be interpreted as
subscription. So why not use curly brackets, "expr{name}"? That doesn't
conflict with anything (currently it's a syntax error), and could be
documented appropriately.

Going back to the regex example, this is how it would look in that case:

    if re.match(exp, string){m}:
        print(m.group(0))

I am currently unsure how it would affect scope. I think it should be
effectively equivalent to a regular assignment statement (and hence follow
identical scope rules), i.e. the above example would be equivalent to the
following in all ways except syntax:

    m = re.match(exp, string):
    if m:
        print(m.group(0))

Thoughts? Please do let me know if there's some critical flaw with this
idea that I missed (or tell me if it's an amazing idea ;)), and just give
feedback, I guess.

Sincerely,
Ken;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180502/26ef9e93/attachment-0001.html>


More information about the Python-ideas mailing list