Hacker News new | ask | show | jobs
by divs1210 1797 days 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.
1 comments

You 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.