TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Writing Elegant Clojure Code Using Higher-Order Functions

30 点作者 mblakele将近 14 年前

2 条评论

praptak将近 14 年前
My favorite example of brevity through higher order functions is:<p><pre><code> (defn flatt­en [x] (appl­y conca­t x)) </code></pre> It flattens one-level of nested lists ( like [[1 2] [3 4]] -&#62; [1 2 3 4]) and even works when x is an infinite generated sequence. On the other hand brevity is not always clarity so HOF tricks should be treated with caution.
评论 #2793291 未加载
ZackOfAllTrades将近 14 年前
A rambling side note:<p>If you come from a javascript background, you will have a leg up on most people in terms of learning clojure. You get used to inlining functions pretty regularly.<p>What I am encountering as I chew through Programming Clojure though is that I had no idea what I could have been doing in javascript all this time. I would look at C and laugh about how they have to define an extra function for event handling. It just seemed so verbose.<p>Looking back at the javascript I wrote/write, I really wish I had understood what I could have been doing with functions, mappings, and apply. I didn't/don't write javascript: it's just C with some in-lined functions.<p>Moral of the story: Inhale the Zen of Crockford(<a href="http://javascript.crockford.com/" rel="nofollow">http://javascript.crockford.com/</a>) and exhale the suck of W3 schools.
评论 #2792415 未加载
评论 #2792411 未加载