This is cool stuff, but it's kind of sad that Python doesn't have any of this stuff.<p>Apparently the Pythonic way to do anything is to repeat yourself, type a lot, implement flatten yourself, and cripple lambdas so no one will want to use them.<p>It's a shame, because there's no reason why Python couldn't be an acceptable language for FP, like Julia. It'll never be great at it of course (just like Julia), but good enough that when I'm doing some ML/stats work in Python, I don't have to rip my hair at because of all the imperative stuff I'm practically forced to do.<p>Python still feels very much like a 90s programming language, except for maybe the async syntax. I'm not sure what exactly went wrong with the development, but the dev team needs to start shaping up or Python risks becoming completely obsolete in the next 5 or 10 years.<p>People might say it's hard to develop a language or whatever, but just look at Julia. Superior in every way imaginable and a much younger language. I've mostly switched over to Julia except for some legacy Python ML projects, and can confidently say there's no reason at all to start a new project in Python.<p>The Python dev team needs to do something drastic if they want Python to survive. They've been slowly boiled alive by conservatism and a host of missteps. I doubt they'll do anything to save Python, but I hope they at least try. Implementing some Coconut features would be a great start.
OMG there are multiline lambdas!!! <a href="https://coconut.readthedocs.io/en/master/DOCS.html#statement-lambdas" rel="nofollow">https://coconut.readthedocs.io/en/master/DOCS.html#statement...</a><p>But trying it out, it doesn't even look like python anymore. Especially if you want to nest them a lot like in other callback heavy languages. It requires a lot of semicolons and parens to get past the parsing ambiguity problem:
<a href="https://stackoverflow.com/questions/1233448/no-multiline-lambda-in-python-why-not" rel="nofollow">https://stackoverflow.com/questions/1233448/no-multiline-lam...</a><p><pre><code> # Incorrect, the lambda returns (y, [1,2,3]) here!
map(def (x) ->
y=x+1;
return y
, [1,2,3])
# Right
map((def (x) ->
y=x+1;
return y
), [1,2,3])</code></pre>
Those who like clojure/lisp, can try with Hy [1]. The latest version removed Python 2 support, but previous versions would work on Python 2 and 3. Can directly run hy code, compile to pyc or readable python source files.<p>For functional programming aficionados that still prefer python, don't forget PyToolz [2] or single-source-file underscore.py [3].<p>[1] <a href="https://docs.hylang.org/en/stable/" rel="nofollow">https://docs.hylang.org/en/stable/</a><p>[2] <a href="https://toolz.readthedocs.io/en/latest/" rel="nofollow">https://toolz.readthedocs.io/en/latest/</a><p>[3] <a href="https://github.com/serkanyersen/underscore.py" rel="nofollow">https://github.com/serkanyersen/underscore.py</a>
I liked the code examples/snippets.<p>I use the Hy language (hylang) when I want a Lisp syntax for Python and I also wrote a book on Hy [1] that can be read for free online.<p>The Python ecosystem, especially for deep learning, is awesome but some of us troublemakers don’t much like Python’s syntax.<p>[1] <a href="https://leanpub.com/hy-lisp-python/" rel="nofollow">https://leanpub.com/hy-lisp-python/</a>
Folks here probably already know, but any time I see functional and python in the same sentence, I like to remind folks about Hy: <a href="https://github.com/hylang/hy" rel="nofollow">https://github.com/hylang/hy</a><p>I think it operates on the AST in python, which is also nifty.
In case you dont want to go hybrid but go all the way: <a href="https://github.com/knocte/2fsharp/blob/master/python2fsharp.md" rel="nofollow">https://github.com/knocte/2fsharp/blob/master/python2fsharp....</a>
If curious see also<p>2016 <a href="https://news.ycombinator.com/item?id=11960692" rel="nofollow">https://news.ycombinator.com/item?id=11960692</a><p>2019 <a href="https://news.ycombinator.com/item?id=18815125" rel="nofollow">https://news.ycombinator.com/item?id=18815125</a><p>and these bits from recent weeks:<p><a href="https://news.ycombinator.com/item?id=23663010" rel="nofollow">https://news.ycombinator.com/item?id=23663010</a><p><a href="https://news.ycombinator.com/item?id=23339351" rel="nofollow">https://news.ycombinator.com/item?id=23339351</a>