[Python-Dev] Language proposal: variable assignment in functional context

Steven D'Aprano steve at pearwood.info
Fri Jun 16 20:27:56 EDT 2017


Welcome Robert. My response below.

Follow-ups to Python-Ideas, thanks. You'll need to subscribe to see any 
further discussion.


On Fri, Jun 16, 2017 at 11:32:19AM +0000, Robert Vanden Eynde wrote:

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

I think this is somewhat similar to a suggestion of Nick Coghlan's. One 
possible syntax as a statement might be:

y = b + 2 given:
    b = a + 1


https://www.python.org/dev/peps/pep-3150/

In mathematics, I might write:

y = b + 2 where b = a + 1

although of course I wouldn't do so for anything so simple. Here's a 
better example, the quadratic formula:

      -b ± √Δ
x =  ─────────
         2a

where Δ = b² - 4ac

although even there I'd usually write Δ in place.


> Python already have the "functional if", lambdas, list comprehension, 
> but not simple assignment functional style.

I think you mean "if *expression*" rather than "functional if". The term 
"functional" in programming usually refers to a particular paradigm:

https://en.wikipedia.org/wiki/Functional_programming


-- 
Steve


More information about the Python-Dev mailing list