FP languages are a lot more than functions being first class citizens. Its also the semantics support, syntactic support, and core language facilities. An FP language is far more than providing Filter, Map, and Reduce.
template<typenameFunction,typename...Arguments>autopartial_application(Functionfunction,Arguments...args){return[=](auto...rest){returnfunction(args...,rest...);};}autoadd6=[](inta,intb,intc,intd,inte,intf)->int{returna+b+c+d+e+f;}autopa1=partial_application(add6,4);autopa2=partial_application(pa1,5);autopax=pa2(10,11,12,13);autoc0=curry(add6);autoc1=c0(4);// sort of kind of like pa1autoc2=c1(5);// sort of kind of like pa2autocx=c2(10)(11)(12)(13);// note that c2 and pa2 are called in very different ways.// cx and pax both equal 55.
OCaml/F#:
let cf a b c d = a * b * c * d
let answer = cf 3 4 5 6
let paf = cf 3 4
let answer2 = paf 3 4
But to JavaScript you'd need to add transitive immutability (as if all objects were made deep frozen at creation, by default, using value semantics like in mathematics), piping, implicit currying, implicit partial application, guaranteed tail recursion (because of immutability),
Yes, you can do FP style programming in JavaScript. And you can also do FP style programming in C, or in C++, or in Lisp. None of those languages are FP languages.
Functional-first FP languages are OCaml, F#, Haskell, Clojure, Elm.
Thanks for the response. My qualm, however, is only with the OPs mention of Javascripts function model. I am making no claims at all regarding where Javascript sits on the functional scale. Infact, I am not claiming Javascript is even a mildly good language for any type of programming. I am simply saying that functions in Javascript are first class constructs.
Maybe I've been misunderstood, but I am lost as to why that is a controversial comment.
FP languages are a lot more than functions being first class citizens. Its also the semantics support, syntactic support, and core language facilities. An FP language is far more than providing Filter, Map, and Reduce.
Compare JavaScript and C++ to OCaml:
JavaScript (ES6):
C++:
OCaml/F#:
But to JavaScript you'd need to add transitive immutability (as if all objects were made deep frozen at creation, by default, using value semantics like in mathematics), piping, implicit currying, implicit partial application, guaranteed tail recursion (because of immutability),
Yes, you can do FP style programming in JavaScript. And you can also do FP style programming in C, or in C++, or in Lisp. None of those languages are FP languages.
Functional-first FP languages are OCaml, F#, Haskell, Clojure, Elm.
Thanks for the response. My qualm, however, is only with the OPs mention of Javascripts function model. I am making no claims at all regarding where Javascript sits on the functional scale. Infact, I am not claiming Javascript is even a mildly good language for any type of programming. I am simply saying that functions in Javascript are first class constructs.
Maybe I've been misunderstood, but I am lost as to why that is a controversial comment.
You are correct. Functions in JavaScript are first class constructs.
(The OP mentioned the Functional Programming Paradigm, which JavaScript falls far short compared to functional programming languages.)