You are a life saver. This is *precisely* what we need. Thank you for 
solving a very difficult problem for us. We were really pulling our hair 
out after searching for a solution.

julia> module Nemo
          import Base: det
          abstract MatElem
          function det(a::MatElem)
             return 1
          end
          type nemomat <: MatElem
          end
          export nemomat
          export det
       end
Nemo

julia> module Hecke
          using Nemo
          import Nemo.det
          type SpecialMat <: Nemo.MatElem
             data::Int
          end
          function det(a::SpecialMat)
             if a.data == 4
                return 3
             else
                return invoke(det, (Nemo.MatElem,), a)
             end
          end
          export SpecialMat
          export det
       end
Hecke

julia> using Hecke

julia> s = SpecialMat(3)
Hecke.SpecialMat(3)

julia> t = SpecialMat(4)
Hecke.SpecialMat(4)

julia> det(s)
1

julia> det(t)
3

Let's help search engines with this, since we were unable to find anything, 
and it is such an important issue:

trouble extending a Base function in Julia
How do I call a specific version of a function in Julia for specific types
How do I call a more general version of a function in Julia
How do I call a less specific version of a function in Julia
How do I call a specific method in Julia
method to apply a function in Julia
invoking a given version of a function in Julia

To the Julia devs: please, please don't remove this functionality!

Bill.

On Tuesday, 28 June 2016 18:40:27 UTC+2, Rafael Fourquet wrote:
>
> I'm far from expert on those questions, but would the "invoke" function 
> work? 
> I think it's considered to be a tool of the last resort, but seems to 
> be the situation you are in! 
>
> invoke(f, (types...), args...) 
>
>   Invoke a method for the given generic function matching the 
> specified types (as a tuple), on the specified arguments. The 
> arguments must be compatible with 
>   the specified types. This allows invoking a method other than the 
> most specific matching method, which is useful when the behavior of a 
> more general 
>   definition is explicitly needed (often as part of the implementation 
> of a more specific method of the same function). 
>

Reply via email to