A simpler version:
(defmacro show [f & args]
(let [f-var# (resolve f)]
`(println ~f-var# (~f ~@args))))
On Friday, May 2, 2014 8:04:30 AM UTC-4, Toby Crawley wrote:
>
> You could implement show as a macro that resolves the var before calling
> the fn:
>
> (defmacro show [f & args]
> (let [f-var# (resolve f)]
> `(let [r# (~f ~@args)]
> (println ~f-var# r#))))
>
> user> (show + 1 2)
> #'clojure.core/+ 3
>
> - Toby
>
> [email protected] writes:
>
> > You need to pass not the function itself, but its Var. Because Vars are
> the
> > ones that hold metadata.
> >
> > (show #'elementary/nothing-but-the-truth true)
> >
> > On Friday, May 2, 2014 4:28:49 AM UTC+2, Erlis Vidal wrote:
> >>
> >> Hi guys,
> >>
> >> I want to write a function (show) that will receive a function as
> >> parameter. How can print the original name of that function? I've tried
> >> with meta, resolve, name but none of them give me the result I want.
> >>
> >> The goal is that I want to write a function that print the name of the
> >> function that will be executed then the result of that execution. If
> >> there's a better way to achieve this I'll appreciate your suggestions.
> >>
> >> Thanks!
> >> Erlis
> >>
> >> (defn show [f sol]
> >> (print (meta f)))
> >>
> >>
> >> (defn -main []
> >> (show elementary/nothing-but-the-truth true))
> >>
> >>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.