TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Coconut: Simple, elegant, Pythonic functional programming

149 pointsby sarahdellyssealmost 5 years ago

11 comments

smabiealmost 5 years ago
This is cool stuff, but it&#x27;s kind of sad that Python doesn&#x27;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&#x27;s a shame, because there&#x27;s no reason why Python couldn&#x27;t be an acceptable language for FP, like Julia. It&#x27;ll never be great at it of course (just like Julia), but good enough that when I&#x27;m doing some ML&#x2F;stats work in Python, I don&#x27;t have to rip my hair at because of all the imperative stuff I&#x27;m practically forced to do.<p>Python still feels very much like a 90s programming language, except for maybe the async syntax. I&#x27;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&#x27;s hard to develop a language or whatever, but just look at Julia. Superior in every way imaginable and a much younger language. I&#x27;ve mostly switched over to Julia except for some legacy Python ML projects, and can confidently say there&#x27;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&#x27;ve been slowly boiled alive by conservatism and a host of missteps. I doubt they&#x27;ll do anything to save Python, but I hope they at least try. Implementing some Coconut features would be a great start.
评论 #23762523 未加载
评论 #23763397 未加载
评论 #23762840 未加载
评论 #23763962 未加载
评论 #23764105 未加载
评论 #23762533 未加载
评论 #23764384 未加载
评论 #23765421 未加载
评论 #23766356 未加载
评论 #23762477 未加载
评论 #23765672 未加载
评论 #23766847 未加载
评论 #23767145 未加载
ghjalmost 5 years ago
OMG there are multiline lambdas!!! <a href="https:&#x2F;&#x2F;coconut.readthedocs.io&#x2F;en&#x2F;master&#x2F;DOCS.html#statement-lambdas" rel="nofollow">https:&#x2F;&#x2F;coconut.readthedocs.io&#x2F;en&#x2F;master&#x2F;DOCS.html#statement...</a><p>But trying it out, it doesn&#x27;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:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;1233448&#x2F;no-multiline-lambda-in-python-why-not" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;1233448&#x2F;no-multiline-lam...</a><p><pre><code> # Incorrect, the lambda returns (y, [1,2,3]) here! map(def (x) -&gt; y=x+1; return y , [1,2,3]) # Right map((def (x) -&gt; y=x+1; return y ), [1,2,3])</code></pre>
评论 #23765152 未加载
评论 #23764834 未加载
评论 #23765745 未加载
dig1almost 5 years ago
Those who like clojure&#x2F;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&#x27;t forget PyToolz [2] or single-source-file underscore.py [3].<p>[1] <a href="https:&#x2F;&#x2F;docs.hylang.org&#x2F;en&#x2F;stable&#x2F;" rel="nofollow">https:&#x2F;&#x2F;docs.hylang.org&#x2F;en&#x2F;stable&#x2F;</a><p>[2] <a href="https:&#x2F;&#x2F;toolz.readthedocs.io&#x2F;en&#x2F;latest&#x2F;" rel="nofollow">https:&#x2F;&#x2F;toolz.readthedocs.io&#x2F;en&#x2F;latest&#x2F;</a><p>[3] <a href="https:&#x2F;&#x2F;github.com&#x2F;serkanyersen&#x2F;underscore.py" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;serkanyersen&#x2F;underscore.py</a>
satvikpendemalmost 5 years ago
Somewhat related is the language Nim: Pythonic, typed, and compiles to native code so it&#x27;s super fast.
评论 #23766248 未加载
mark_l_watsonalmost 5 years ago
I liked the code examples&#x2F;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:&#x2F;&#x2F;leanpub.com&#x2F;hy-lisp-python&#x2F;" rel="nofollow">https:&#x2F;&#x2F;leanpub.com&#x2F;hy-lisp-python&#x2F;</a>
codezeroalmost 5 years ago
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:&#x2F;&#x2F;github.com&#x2F;hylang&#x2F;hy" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;hylang&#x2F;hy</a><p>I think it operates on the AST in python, which is also nifty.
knoctealmost 5 years ago
In case you dont want to go hybrid but go all the way: <a href="https:&#x2F;&#x2F;github.com&#x2F;knocte&#x2F;2fsharp&#x2F;blob&#x2F;master&#x2F;python2fsharp.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;knocte&#x2F;2fsharp&#x2F;blob&#x2F;master&#x2F;python2fsharp....</a>
dangalmost 5 years ago
If curious see also<p>2016 <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=11960692" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=11960692</a><p>2019 <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=18815125" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=18815125</a><p>and these bits from recent weeks:<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23663010" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23663010</a><p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23339351" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23339351</a>
vmchalealmost 5 years ago
Cool stuff! Python&#x27;s ecosystem for data science is amazing, it&#x27;s definitely good to be able to use a functional language with them.
wendyshualmost 5 years ago
I&#x27;ve used it in the past but there were subtle interoperability issues with existing python libraries and I gave up.
cutleralmost 5 years ago
&quot;... compiles to Python&quot;? Am I missing something or shouldn&#x27;t this just be a library?
评论 #23764124 未加载