3 ms·
Oddly enough I never used this, but maybe named fns might help? (http://clojure.org/special_forms#Special%20Forms--%28fn%20name?%20%28[params*%20]%20exprs*%29+%
by calibraxis 12y ago
Oddly enough I never used this, but maybe named fns might help? (http://clojure.org/special_forms#Special%20Forms--%28fn%20name?%20%28[params*%20]%20exprs*%29+%29 http://clojure.org/special_forms#Special%20Forms--%28fn%20na...)
(fn my-name []
(throw (Exception. "boom")))
(Sorry, I don't know Clojure internals well enough to have great answers to your explicit questions.)
[Edited: thanks to jerf for pointing out the inconsistency in a term I used.]
- jerf 12y agoNamed... anonymous... functions? Wuzzah fuzzah?
- weavejester 12y agoThey allow you to use recursion without the need for a Y-combinator.
- larholm 12y agoJust like in Javascript.
- awj 12y agoYeah, that's a terminology issue. They mean lexically scoped named functions. Versus the default in Clojure of global or namespace scope.
- emidln 12y agoNamed anonymous functions are there to allow you to call the function recursively while inside it. i.e. (= ((fn factorial [x] (if (<= x 1) 1 (* x (factorial (dec x))))) 5) 120) Note, this isn't run under TCO (see loop/recur).
- ufo 12y agoAlso, in your example, the recursive call is not in tail position. You would first need to rewrite it to use an acumulator parameter.