4 ms·
I'd be hard-pressed to call Javascript a "functional programming language" (whatever that means). Common Lisp also suffers from the same misguided label. In tru
by agentultra 13y ago
I'd be hard-pressed to call Javascript a "functional programming language" (whatever that means). Common Lisp also suffers from the same misguided label. In truth we love to mutate state in CL and find lattices of type hierarchies to be burdensome (but a great pool of research for your post-doc).
Scheme is about as close as I'll get to pure-FP languages. I don't seem ES6 going down the "purity," route. And I hope it stays far from the border.
What I was originally referring to though is (if I recall the history of the language) the roots of Javascript -- that it purportedly was a Scheme-like language before becoming what it is today. And by being what it is now has lagged behind in feature-parity to what programmers are used to in other languages whose history isn't tied to the venerable web browser. It just seems to me from the interviews that skirt the topic that Mr. Eich is finally coming back around to introduce what should have been there from the start.
(Updated for clarity)
- AlexanderDhoore 13y agoOf course, it's not Haskell... I'm very aware that Javascript was inspired by Scheme. The lexical scoping for example, is obviously "functional" (indeed, whatever that means). Now they are introducing ways to more easily work with lists. Only thing missing is tail call optimization!
- coldtea 13y ago>I'm very aware that Javascript was inspired by Scheme. The lexical scoping for example, is obviously "functional" (indeed, whatever that means). No it wasn't. That's an urban legend. Eich WANTED to make a Scheme for the browser -- he didn't get a permission to do it, and made Javascript instead, which is actually inspired from other languages like Self. Nothing functional about Javascript's horribly broken scoping either... http://journal.stuffwithstuff.com/2013/07/18/javascript-isnt-scheme/ http://journal.stuffwithstuff.com/2013/07/18/javascript-isnt...
- MatthewPhillips 13y agoYou could use const all over the place.
- AlexanderDhoore 13y agoStill doesn't give you immutable data structures though. For example: const myArray = [42]; myArray.push("Oh noes"); [42, "Oh noes"]
- MatthewPhillips 13y agoUgh, you're kidding? EDIT: checked in Node, yep. That's unfortunate. Can we get a let foo immutable = [1]; or something? EDIT2: Although this can be implemented in user-land with Object.freeze. Create a function that returns a const that is frozen if it is non-primitive. That should cover it, right?
- kevingadd 13y agofreeze/seal don't actually provide true immutability in JS. There are cases where a frozen object can still be modified (Date is one of them, IIRC typed arrays are another)
- tensor 13y agoClojureScript provides truly immutable data structures that compile down to javascript. You can use them from JS: https://github.com/swannodette/mori https://github.com/swannodette/mori