> De: "Sean Corfield"
> À: "clojure"
> Envoyé: Jeudi 29 Avril 2021 01:26:34
> Objet: Re: How get function name in body?
> Consider that:
> (defn add [a b] (+ a b))
> is expanded to (something like):
> (def add (fn [a b] (+ a b)))
> So the actual code that runs is an anonymous function, which
That's definitely nicer:
dev=> (*defn* *add* [a b]
#_=> (*println* (demunge (*.getName* (*.getCallerClass* (
*java.lang.StackWalker*/getInstance *java.lang.StackWalker$Option*
/RETAIN_CLASS_REFERENCE)
#_=> (*+* a b))
#'dev/add
dev=> (add 1 2)
dev/add
3
dev=>
Thanks, Rémi!
On Thu
Clojure 1.10.1
(defn haha []
(println (demunge (.getName (.getCallerClass
(java.lang.StackWalker/getInstance
java.lang.StackWalker$Option/RETAIN_CLASS_REFERENCE))
Syntax error compiling at (REPL:1:23).
Unable to resolve symbol: demunge in this context
在2021年4月30日星期五 UTC+8 上
Sorry, it's clojure.repl/demunge so it depends on how you run your REPL and
evaluate code -- in my case, clojure.repl symbols were all referred in. In
your case, you'll need to require clojure.repl and refer it in:
(require '[clojure.repl :refer [demunge])
or make that part of your ns form as: