问题
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?
回答1:
Well, first of all, there is the identity
function.
But you can use
#(do %)
if you insist.
来源:https://stackoverflow.com/questions/9148896/in-clojure-how-to-write-the-identity-function-using-the-anonymous-function-lite