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

unlo...@bytopia.org 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 clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to