Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between the fn and # syntax for anonymous functions in Clojure?

I'm new to clojure, and I've seen anonymous functions written like:

(fn [x] (* x x))

and also like:

#(* % %)

Obviously, the second is more concise. Is there any relevant difference? Can every anonymous function be represented in either style? Is one more idiomatic?

Related to this question, I was unable to determine how to convert (fn [x] [x x]) to the latter syntax. I would appreciate a pointer to documentation that clarifies this situation.

like image 554
Eric Wilson Avatar asked Oct 02 '12 01:10

Eric Wilson


People also ask

What gun is better FN or Glock?

From a distance, the FN 509 beats the Glock, but up close, the Glock Gen 5 frame feels higher quality. Not to mention, the Gen 3 and 4 frames feel similar to the FN 509. Overall, the quality on the FN seems higher than the quality on the Glock.

What is the difference between FN 509 and 509 tactical?

There are only a couple differences from the standard FN 509. The primary difference between the FN 509 Tactical and the standard 509 is the 509 Tactical adds a threaded, extended barrel, and the slide is milled for use with a reflex optic adapter plate. The pistol comes with a plate with a rear sight shroud.

Are FN guns any good?

FN is known for making quality weapons that primarily do well in the military market, not the civilian market. So when FN introduced the FN 509 as an improved version of the FN FNS many were skeptical of how well it would do on the civilian market considering FN's poor track record.


1 Answers

Another SO answer (Common programming mistakes for Clojure developers to avoid) mentions that #([% %]) expands to fn [%] ([% %]) (note the parentheses), which causes an ArityException.

You can do #(vector % %) to workaround this limitation.

like image 141
brianpeiris Avatar answered Sep 29 '22 10:09

brianpeiris