4 ms·
If we're playing code golf, then in Clojure it is: (def bar #(+ % 1)) or even (def bar inc) but the difference is that in Clojure, all of these are
by divs1210 5y ago
If we're playing code golf, then in Clojure it is:
(def bar #(+ % 1))
or even
(def bar inc)
but the difference is that in Clojure, all of these are `IFn`s, and have the same calling syntax, unlike Elixir.
- AlchemistCamp 5y agoYou may be "playing code golf", but I generally just use the capture syntax where the compactness aids readability. For example, a function that takes two arguments and returns their product could be written as fn x, y -> x * y end or &(&1 * &2) When used inside a map or reduce or when the function is a direct mathematical operation on its arguments, it can be a bit quicker to parse the capture syntax than the fn ... end syntax.