how to detect a "callable" following the changes introduced by #13412

192 views
Skip to first unread message

Jeff Waller

unread,
Feb 4, 2016, 2:18:20 AM2/4/16
to julia-dev
So yea, I think I have some catching up to do.

With the  merge of #13412 the marco jl_is_function (formerly in julia.h) no longer exists, but jl_function_t still does, so if
a value not a function, then what is it now? 

Previously, my purpose is to loop over all the globals in a module and add all the functions in a list and make
them callable externally.

         jl_value_t *val = jl_get_global(module,jl_symbol(s->c_str()));


         if(val && jl_is_function(val)) filteredNames.push_back(*s);


then some stuff....


My question now is what to do instead?  Are some things still functions and others something different?

Jeff Bezanson

unread,
Feb 4, 2016, 10:24:21 PM2/4/16
to juli...@googlegroups.com
Since "call overloading" was introduced in v0.4, it has been possible
for any object to be "called" like a function. So one now needs to be
a bit more specific about what "function" means. The most direct test
is "are there any methods present?", which can be checked by
`!isempty(methods(f))`. Or `jl_gf_mtable(f)->defs != jl_nothing`.

Or, if an object is intended to be a function but doesn't have methods
yet, e.g. defined by `function f end`, then you can check `isa(f,
Function)`, where `Function` is now an abstract type.

Jeff Waller

unread,
Feb 5, 2016, 11:23:43 PM2/5/16
to julia-dev
Fixed; much thanks, I opted for preserving the notion of the test knowing that for my application
for now all of the new possibilities are not encountered.

#if !defined(jl_is_function)
#define jl_is_function(v) ((jl_value_t*)jl_gf_mtable(v)->defs != jl_nothing)
#endif


Reply all
Reply to author
Forward
0 new messages