How could one write the identity function in clojure using anonymous function literal (#())?
The following code doesn’t work:
(#(%) 5)
It raises an exception because it is converted to:
((fn[x] (x)) 5)
The problem in that when using #(), the function body is enveloped with parentheses.
Any idea, how to elegantly overcome this?
Well, first of all, there is the
identityfunction.But you can use
if you insist.