Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure: determine if a function exists

Tags:

clojure

lisp

how can i know if a function name provided as string is callable or not in the current context? something like:

(callable? "asdasd") ;; false
(callable? "filter") ;; true

thanks

like image 809
pistacchio Avatar asked Oct 10 '11 16:10

pistacchio


1 Answers

You are looking for resolve,

(resolve (symbol "asd"))

returns nil

(resolve (symbol "filter"))

return #'clojure.core/filter

To check if a var is a function (credit goes to @amalloy):

(-> s symbol resolve deref ifn?)
like image 60
Hamza Yerlikaya Avatar answered Oct 13 '22 06:10

Hamza Yerlikaya