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;
I kind of strangely like this, but it does something completely different from parens or []. Those do have something in common - func(param) and indexable[index] both result in some value obtained in some way by combining the two names - either it's the result of func when called with param, or it's the some part of indexable identified by index. expr{name} would have a value equal to that of expr, and actually change name (and the change to the contained name is something [] never does (AFAIK), and I daresay most people would agree a function call shouldn't either.)
On 02/05/18 07:21, Ken Hilton wrote:
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))
The various other options at least suggest that in some manner what is going on is an assignment. This really doesn't. Sorry, it's just too magic.