4 ms·
For your second example, your JavaScript is wrong. Let's compare the ES2015 JavaScript: ((a, b) => a * b)(6, 4); ...against the Clojure: ((fn [a b] (* a
by bshimmin 9y ago
For your second example, your JavaScript is wrong. Let's compare the ES2015 JavaScript:
((a, b) => a * b)(6, 4);
...against the Clojure:
((fn [a b] (* a b)) 6 4)
Not a lot in it, really, is there?
- lilactown 9y agoIf we're golfing... (#(* %1 %2) 6 4)
- smnplk 9y agoAnd a bit shorter version... 24 ;)
- mrkgnao 9y agoI wonder, does #(* %1) do anything sensible?
- kbp 9y ago> I wonder, does #(* %1) do anything sensible? It's a 1-argument function, so applying it to 2 arguments would give an error. Minus the arity error, 1-argument * is an identity.
- latte 9y agoClojure's * can accept any number of arguments, including zero (returns 1 in this case), one (acts as identity function on numbers) or more than two (returns the product of all arguments). This helps to simplify arithmetic expressions in some cases (e. g. polynominals) and allows to calculate a sum or product of any sequence, including empty one, using (reduce * xs)
- dragandj 9y agoThe clojure example is really (* 6 4) since * is already a function, not an operator as in most languages. On the other hand, you can trivially create a macro that would implement the exact es2015 syntax (or at least a very close match), but why would anyone do this?