Fork me on GitHub

You now have the unique chance to be in a #babashka workshop given by @rahul080327!

Daniel Gerson17:11:52

Question: I've never seen the notation of this function as part of the clojure language with accept as the first symbol before the argument vector. . Is it just ignored or does it have some significance? :thinking_face: Scanning I don't see it. So curious.


In JVM Clojure, if provided, it’s used in the generated class name, so it is helpful to disambiguate between anonymous functions when reading stacktraces:

dev> (fn [])
dev> (fn my-cool-fn [])
Not sure how that works in Babashka.

Daniel Gerson17:11:26

Thanks! Wish it was on the Clojure functions page.


Also provides for self-reference without recur if your recursion is already stack-safe.

(let [foo (fn bar [x]
            (if (> x 1) x (bar (inc x))))]
  (foo 0))
; => 2

Alex Miller (Clojure team)18:11:23

that's rarely a good usage - here you could safely recur instead. and let-fn is sufficient for mutually recursive local functions. really the primary reason to name your fn is to share intent and to aid debuggability


Yes. The example is terrible use case, which is definitely not stack safe. It was just a quick & dirty demonstration of the capacity to call the name recursively. I have pretty mixed feelings about let-fn. In addition to it's lack of symmetry with the syntax of let, it can get verbose quickly if you also want non-function let bindings. If I don't specifically need mutual recursion, I am personally inclined to avoid it.

Bob B19:11:18

regarding the docs themselves, as you mentioned the optional name is not covered in the "learn Clojure" page (which I assume is because it's not typicaly heavily used to get started), but it is covered in the reference: <>

👍 1
Alex Miller (Clojure team)19:11:12

I actually think it's kind of accidental that it does work, which may be why it was not part of the original docs

👀 1