As Clojure programmers we use lots of anonymous functions without thinking it's cost.
What are the relative costs of creating and using anonymous functions in clojure?
Clojure compiles all functions, anonymous or named, the same way. It then stores a pointer to that function in a namespace (contained in a var) so others can find it later.
There is no cost difference in compile time between functions that are compiled and used as anonymous functions, vs functions that are compiled, then have a pointer to them stored in a var that is part of a namespace.
When anonymous functions used at runtime, most of the time (perhaps always) they are created by making closures (the objects) so the cost of creating them is some memory and a little time.
If you are calling eval in time critical loops of course you can create the same problems in Clojure that you can make in any other language.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With