3 ms·
Sure, Javascript has first class functions, which I guess meets the bare minimum requirements for being a functional language, but it also lacks some key featur
by fbonetti 11y ago
Sure, Javascript has first class functions, which I guess meets the bare minimum requirements for being a functional language, but it also lacks some key features:
* Pure functions - JS functions are essentially subroutines. They might return a useful value or they might mutate a bunch of stuff and interact with the outside world. Who knows? JS functions aren't guarunteed to return the same value, or any value at all.
* Immutability - Anything and everything can be mutated in JS, including the contents of objects that are defined using the new ES6 `const` keyword
* Curried functions by default - Although it's possible to compose or partially apply JS functions, it's not nearly as nice as Haskell or Elm.
- klibertp 11y agoYou're influenced by only one part of FP world. Let's take Lisp, or even better: Scheme. * pure functions - all you said is equally true for Scheme * immutability - set-cdr! and many SRFIs: vectors, boxes, records... * curried by default - nope, not in Scheme either There are other flavours of FP languages other than ML descendants. They are not "less functional" at all.
- chc 11y agoIt's true, not every language goes all-in on functional programming — but just because some functional languages are less strongly functional than others, that doesn't mean it makes sense to call every language currently in use a functional language. I mean, it seems pretty useless to define "functional programming language" in a way that includes both C and OCaml just because you can pass functions around in both of them.