How to determine if an object is callable?

question

#1

How do I determine if an object is callable?


#2

#3
v0.6.0-pre.alpha.179> callable(o) = !isempty(methods(o))
callable (generic function with 1 method)

v0.6.0-pre.alpha.179> is_not_callable = 1
1

v0.6.0-pre.alpha.179> is_callable(x) = 1
is_callable (generic function with 1 method)

v0.6.0-pre.alpha.179> callable(is_not_callable)
false

v0.6.0-pre.alpha.179> callable(is_callable)
true

#4

Bool can convert only 0 and 1 to a boolean:

julia> callable(sin)
ERROR: InexactError()
Stacktrace:
 [1] convert(::Type{Bool}, ::Int64) at ./bool.jl:7
 [2] callable(::Function) at ./REPL[9]:1

#5

Oh ok, thanks :wink: