Thanks everyone.
A bit more context: I'm trying to implement callbacks in RCall.jl. There
are multiple ways R objects could be converted to Julia ones (as
singletons, vectors, Nullable singletons/vectors, dictionaries, etc.), so
what I was thinking was:
1) pass the R objects (known as SEXPRECs) straight to the Julia method
2) the first time a Julia function is converted to an R object (via the
sexp function), I wanted to define an initial generic method which would
take SEXPRECs and perform a default conversion.
function sexp(f::Function)
if method_defined(f,(VarArgs{SEXPREC},))
global f
f(x::SEXPREC...)
y = rcopy(...) # do default conversions
f(y...)
end
end
return callback(f) # construct R object for callback
end
In that way if a user wanted a different conversion, they could define
their own method(s) to do this. But I don't want to overwrite this if it
already exists.
Any ideas?
-Simon
On Monday, 6 July 2015 19:09:43 UTC+1, Mauro wrote:
>
> If I understand correctly what you want, then have a look at Traits.jl
> where I check method signatures of trait-definitions against methods of
> a generic function. See the loop at:
> https://github.com/mauro3/Traits.jl/blob/master/src/Traits.jl#L158 and
> in particular isfitting.
>
> Turns out that this is a relatively hard problem (unless I made a mess
> of it), in particular once parametric methods are involved. However,
> your problem might be a bit easier than what Traits does as it test for
> equality. Let me know if you got questions.
>
> On Mon, 2015-07-06 at 19:25, Simon Byrne <[email protected] <javascript:>>
> wrote:
> > If I have a generic method foo, is there a way I can tell if a
> particular
> > signature has been defined?
> >
> > Note that I don't want method_exists (which simply determines if
> something
> > can be dispatched), I want to determine if a particular definition has
> been
> > made, e.g. if
> >
> > foo(x) = x
> >
> > then I want
> >
> > method_defined(foo,(Int,)) == false
> > method_defined(foo,(Any,)) == true
>
>