Hello, I would like to propose an idea for the language but I don't know where 
I can talk about it.

In a nutshell, I would like to be able to write:
y = (b+2 for b = a + 1)

Or in list comprehension:
Y = [b+2 for a in L for b = a+1]

Which can already be done like this:
Y = [b+2 for a in L for b in [a+1]]

Which is less obvious, has a small overhead (iterating over a list) and get 
messy with multiple assignment:
Y =  [b+c+2 for a in L for b,c in [(a+1,a+2)]]

New syntax would allow to write:
Y =  [b+c+2 for a in L for b,c = (a+1,a+2)]

The parenthesis are needed for syntax reason I think.

One could have successive assignements

My first example (b+2 for b = a+1) can already be done using ugly syntax using 
lambda

y = (lambda b: b+2)(b=a+1)
y = (lambda b: b+2)(a+1)
y = (lambda b=a+1: b+2)()

Choice of syntax: for is good because it uses current keyword, and the analogy 
for x = 5 vs for x in [5] is natural.

But the "for" loses the meaning of iteration.
The use of "with" would maybe sound more logical.

Python already have the "functional if", lambdas, list comprehension, but not 
simple assignment functional style.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to