This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-22
Channels
- # aleph (5)
- # announcements (9)
- # babashka (9)
- # beginners (127)
- # cherry (1)
- # cider (48)
- # clj-kondo (5)
- # cljdoc (1)
- # clojure (70)
- # clojure-berlin (1)
- # clojure-europe (57)
- # clojure-france (2)
- # clojure-germany (1)
- # clojure-nl (2)
- # clojure-norway (4)
- # clojure-uk (1)
- # clojurescript (2)
- # css (1)
- # cursive (6)
- # emacs (6)
- # gratitude (1)
- # honeysql (5)
- # introduce-yourself (5)
- # jobs-discuss (7)
- # joyride (1)
- # kaocha (3)
- # lsp (1)
- # malli (9)
- # nbb (2)
- # off-topic (91)
- # pathom (7)
- # pedestal (14)
- # re-frame (4)
- # reitit (67)
- # shadow-cljs (46)
- # spacemacs (3)
- # squint (3)
- # tools-build (14)
- # tools-deps (1)
- # vim (3)
You now have the unique chance to be in a #babashka workshop given by @rahul080327!
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. https://github.com/babashka/fs/blob/master/test/babashka/fs_test.clj#L212 . Is it just ignored or does it have some significance? :thinking_face: Scanning https://clojure.org/guides/learn/functions 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 [])
#function[dev/eval325607/fn--325608]
dev> (fn my-cool-fn [])
#function[dev/eval325611/my-cool-fn--325612]
Not sure how that works in Babashka.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
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.
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: <https://clojure.org/reference/special_forms#fn>
I actually think it's kind of accidental that it does work, which may be why it was not part of the original docs