How to check that a Symbol represents a function

Hello

I want to go through all the names in a module and find out those that represent a function.
I tried something like:

typeof(eval(:foo))

and in case :foo is a function, it returns:

typeof(foo)

From this I can see (with my eyes) that it is a function, but I can’t figure out how to see it in Julia.
Could you tell me how to see if a Symbol represents a function?

Thanks,

Michel

2 Likes

getfield is what you’re wanting:

julia> foo(x) = x
foo (generic function with 1 method)

julia> isa(getfield(Main, :foo), Function)
true

isdefined(Main, :foo) can be helpful too to make sure the binding actually exists before using getfield.

6 Likes

Thanks!
Very nice!
Never imagined that a module had fields … I like Julia.
Michel

alternatively

julia> isa(eval(:foo), Function)
true
2 Likes

Thanks!