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...
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> .
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?
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));
It never occurred to me to try some currying in CoffeeScript, but man this looks expressive:<p><pre><code> f = (x) -> (y) -> x + y
g = f 6</code></pre>
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.
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 & 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.
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>
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.
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?
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>
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.
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.
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 ?