Language proposal: variable assignment in functional context
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.
2017-06-16 13:32 UTC+02:00, Robert Vanden Eynde <robertvandeneynde@hotmail.com>:
Hello, I would like to propose an idea for the language but I don't know where I can talk about it.
Hi, May I suggest Python-ideas? https://mail.python.org/mailman/listinfo/python-ideas Thanks.
Thanks! Le 17 juin 2017 06:19, "Shloub" <shloub@gmail.com<mailto:shloub@gmail.com>> a écrit : 2017-06-16 13:32 UTC+02:00, Robert Vanden Eynde <robertvandeneynde@hotmail.com<mailto:robertvandeneynde@hotmail.com>>:
Hello, I would like to propose an idea for the language but I don't know where I can talk about it.
Hi, May I suggest Python-ideas? https://mail.python.org/mailman/listinfo/python-ideas Thanks.
Thanks! Le 17 juin 2017 06:19, "Shloub" <shloub@gmail.com<mailto:shloub@gmail.com>> a écrit : 2017-06-16 13:32 UTC+02:00, Robert Vanden Eynde <robertvandeneynde@hotmail.com<mailto:robertvandeneynde@hotmail.com>>:
Hello, I would like to propose an idea for the language but I don't know where I can talk about it.
Hi, May I suggest Python-ideas? https://mail.python.org/mailman/listinfo/python-ideas Thanks.
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
participants (4)
-
Erik
-
Robert Vanden Eynde
-
Shloub
-
Steven D'Aprano