3 ms·
Almost all programming languages are imperative. However, you can often program in a declarative style and some languages lend themselves better to this than ot
by dkersten 12y ago
Almost all programming languages are imperative. However, you can often program in a declarative style and some languages lend themselves better to this than others (either for technical or culture reasons).
Clojure is, at its core, imperative. Functional programming is not, IMHO, in itself declarative. To me, functional is just an approach to imperative programming.
Something like prolog is declarative: you tell it some rules and relationships (constraints on your data) and let it find the data which matches this. You declare the rules, it gives you the results. That's declarative: relationships, constraints, rules - not steps (functional, procedural or otherwise).
Clojure does lend itself quite well to declarative programming though. Partially because of its features (macros/metaprogramming, functional programming and immutability makes it easier too) and partially because of the community culture (emphasis on the data etc) and this can be seen in the libraries that have emerged in the ecosystem: core.logic is essentially embedded prolog, core.match lets you extract data declaratively, various datalog-esque libraries (eg Dataomic) to query data declaritively and others that I'm forgetting.
So in summary: I agree that Clojure isn't in itself declarative, but it is quite well suited to programming in a declarative style.