News for hackers. Stuff that matters.
Re:Once you go functional, you can never go back by RodgerTheGreat on Monday May 18, 2015 @09:23AM (#9564240)
> 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.
Re:Once you go functional, you can never go back by okasaki on Monday May 18, 2015 @09:55AM (#9564404)
No idea why the author thinks it's impossible. I mean, C stdlib comes with qsort.

Here's a map in C

    void *map(void *in, void (*f)(void *src, void *dst), size_t size, size_t in_s, size_t out_s)
    {
        void *out = malloc(size * out_s);
    
        for(size_t i = 0; i < size; i++)
            f(in + (i * in_s), out + (i * out_s));
    
        return out;
    }
Re:Once you go functional, you can never go back by Kenji on Monday May 18, 2015 @09:47AM (#9564371)
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!
Re:Once you go functional, you can never go back by agumonkey on Monday May 18, 2015 @11:10AM (#9564883)
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.

Re:Once you go functional, you can never go back by Nemcue on Monday May 18, 2015 @09:59AM (#9564426)
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.
Re:Once you go functional, you can never go back by braythwayt on Sunday May 31, 2015 @04:07AM (#9633448)
Actually, the original version of this book is no longer for sale. The link for the updated free version is here: https://leanpub.com/javascriptallongesix/read

Or, if you want to buy it in other formats, here: https://leanpub.com/javascriptallongesix

Re:Once you go functional, you can never go back by Bognar on Monday May 18, 2015 @09:41AM (#9564333)
Also, for C# IEnumerables, .Select() is map and .Aggregate() is reduce.