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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Functional Programming in 5 Minutes

160 点作者 gsklee大约 12 年前

20 条评论

nlh大约 12 年前
As a still-learning programmer, can someone point me towards the ELIF (Explain Like I'm Five) version of this? Some of the first questions that enter my mind after reading this intro --<p>Why is this relevant? Why do we as programmers want to know about pure functional programming? What are its advantages? What's the point? This seems to add complexity. Etc.<p>I know there are good answers to these, but this intro has done little more than whet my appetite a bit...
评论 #5733555 未加载
评论 #5733577 未加载
评论 #5733452 未加载
评论 #5733500 未加载
评论 #5734174 未加载
评论 #5734142 未加载
elpool2大约 12 年前
Not a very good intro to functional programming or currying mostly because it never explains WHY you would ever want to use currying.
评论 #5735314 未加载
评论 #5734584 未加载
gokhan大约 12 年前
That slid.es presentations are really pretty. It seems it's from <a href="http://hakim.se/" rel="nofollow">http://hakim.se/</a> , You may remember his experiments here <a href="http://www.hakim.se/experiments" rel="nofollow">http://www.hakim.se/experiments</a> .
评论 #5733759 未加载
评论 #5735187 未加载
peter-fogg大约 12 年前
I think the title is a bit misleading. Perhaps "a quick explanation of one common feature of functional languages in five minutes" would be more appropriate?
im3w1l大约 12 年前
It would have been great to have a real world example when currying/uncurrying would have been useful.
johnnyg大约 12 年前
He lost me here:<p>function g(h) { return function(y) { return h(h(y)); }; }<p>81 === g(function(x) { return x * x; })(3);<p>Specifically, why is this allowed and where can I go read about it?<p>return h(h(y));
评论 #5734431 未加载
评论 #5734889 未加载
chenglou大约 12 年前
It never occurred to me to try some currying in CoffeeScript, but man this looks expressive:<p><pre><code> f = (x) -&#62; (y) -&#62; x + y g = f 6</code></pre>
评论 #5733893 未加载
Falling3大约 12 年前
This is a really excellent presentation. It got me to finally make the connection between currying and closures - I think that was the missing awesome piece I was missing for really understanding the importance of closures.
tegeek大约 12 年前
IMO currying is a bit advance idea for non-functional programmers. If I were to explain functional programming in 5 min, I would start from Functions and Values.<p>In FP, there is no difference between a Function and a Value. A function can be defined without a name. You can say every thing is a function &#38; a function takes an input and after performing its magic (calculations), it must return you an output. All values are also functions. So technically there is no difference between x = 2 and x = function(){....}.<p>Now when you realize that all values are also functions or all functions are also values, you can pass functions inside other functions. Typically in imperative programming your functions only accepts values (like integers, strings etc.) and returns you values. But in FP you can pass functions inside other functions and you can return functions from functions.<p>Lets define a function doSomething(input){ return input } . Now you can call it by passing x where x could be a value or a function.<p>y = doSomething(x)<p>Now if x = function(){ ..} or x = 2, it really doesn't matter for doSomething because doSomething crunches an input and returns it.<p>By learning this technique, you can do lot of "interesting things". And Currying is one of those "interesting things". Every thing in FP really boils down to functions/values. 5 mins are over now.
tiglionabbit大约 12 年前
Currying is stupid. It's more complicated and less flexible than just explicitly defining a new function. For example, try to do this with currying:<p><pre><code> var x = function(a,b,c){ return a - b * c }; var y = function(a,b) { return x(a, b, 5) }; </code></pre> Also, currying is married to positional arguments. What if you're trying to use keyword arguments? Can you curry this?<p><pre><code> var x = function(params) { return params.top - params.bottom; }</code></pre>
dclowd9901大约 12 年前
If you're like me, this was a little odd:<p>function g(x) { return function(y) { return x + y; }; }<p>f(1, 2) === g(1)(2);<p>How does this work? Since the function g is itself also returning a function, the call g(x) is itself literally another function address (if you will) awaiting an additional parameter with an invisible (y) on the end.<p>I have been dabbling in functional programming for a short while now, but this one took me completely by surprise. I had no idea JS would pass a function like that.
评论 #5736208 未加载
ezraroi大约 12 年前
Nice overview for 5 minutes, but you will need a lot more to really understand functional programming
评论 #5733516 未加载
SonicSoul大约 12 年前
this is great! (both because of content and presentation tool)<p>so why is there a limitation of just one argument? since lambda expressions can receive multiple arguments, and simply resolve them in order, why can't functional programming do the same? is this just a stylistic thing?
评论 #5734160 未加载
akst大约 12 年前
Here's another fun walkthrough that was posted here a little while ago. <a href="http://stevelosh.com/blog/2013/03/list-out-of-lambda/" rel="nofollow">http://stevelosh.com/blog/2013/03/list-out-of-lambda/</a>
GhotiFish大约 12 年前
As I'm already familiar with currying, the highlight of this slideshow had to be the slideshow. That is a pretty slideshow!<p>That said. Looks like they hold your slides hostage if you don't pay. Scary.
评论 #5734252 未加载
peteretep大约 12 年前
Can someone explain to me like a child what makes JavaScript more "functional" than any of the many, many, many other languages that offer anonymous code blocks? kthnx.
评论 #5735822 未加载
leke大约 12 年前
This gave me an AHA! moment. I really like it when tutorials can do that. Thanks gsklee, I'll be keeping an eye on you ;)
评论 #5735129 未加载
hsmyers大约 12 年前
Not enough for an epiphany, but enough to try until understanding occurs. Not bad for &#60;5 minutes!
apunic大约 12 年前
OT: this slid.es presentations are even on Mobile Safari so butter smooth like native apps.
camus大约 12 年前
Want to learn functionnal programming , just download GCL<p><a href="http://www.cs.utexas.edu/users/novak/gclwin.html" rel="nofollow">http://www.cs.utexas.edu/users/novak/gclwin.html</a><p>check out a few Lisp tutorials on Youtube and you good to go. Dont try to apply fuctionnal principles to procedural languages , if you are a beginner.<p>Using Lisp will force you to do and understand functionnal programming. And frankly , Lisp is a lot of fun and easy to start with. Dont be afraid by all these nasty (()) and weird (+ 4 5) operations , it will make sense quite fast.<p>something like<p><pre><code> (defun add(a b) (+ a b)) (add 4 5) </code></pre> is actually easy to understand , isnt it ?
评论 #5733605 未加载
评论 #5733558 未加载
评论 #5734206 未加载