> Since this is impossible in imperative languages, I can't give you a comparison.
I'll bite. Here's foldr() in JavaScript, written in an imperative style:
function foldr(func, list) {
var r = [];
for(var index = list.length-1; index >= 0; index--) {
r = func(list[index], r);
}
return r;
}
It isn't defined via pattern matching, but it's absolutely a higher-order function. Functional programming is a collection of ways of thinking about problem solving, and it can be applied to any language.
I like what you are doing here. Since I've been introduced to Haskell, I wondered about functional programming in JavaScript. To my surprise, JavaScript is versatile enough to support a lot of functional concepts!
All these languages have a similar enough semantic core which if you remove assignments and use mostly closures/hof you end up with a syntactically heavy[1] untyped ML (sic). {Coffee,Live}script comes to mind.
[1] remove return, curly braces .. with ES6 unpacking/pseudo-pattern-matching and let, you're half way there.
I can recommend flicking through https://leanpub.com/javascript-allonge/read -- it's a really good book on functional programming in JS. Ends up doing Ycombinators, trampolining etc.
I'll bite. Here's foldr() in JavaScript, written in an imperative style:
It isn't defined via pattern matching, but it's absolutely a higher-order function. Functional programming is a collection of ways of thinking about problem solving, and it can be applied to any language.