我想知道是否有一种方法可以使用Symbols进行多次调度,但是还包括“全部捕获”方法。即像



function dispatchtest{alg<:Symbol}(T::Type{Val{alg}})
  println("This is the generic dispatch. The algorithm is $alg")
end
function dispatchtest(T::Type{Val{:Euler}})
  println("This is for the Euler algorithm!")
end


第二个可以使用并与手册中的内容相匹配,我只是想知道您如何使第一个可以使用。

最佳答案

您可以这样操作:



julia> function dispatchtest{alg}(::Type{Val{alg}})
           println("This is the generic dispatch. The algorithm is $alg")
       end
dispatchtest (generic function with 1 method)

julia> dispatchtest(alg::Symbol) = dispatchtest(Val{alg})
dispatchtest (generic function with 2 methods)

julia> function dispatchtest(::Type{Val{:Euler}})
           println("This is for the Euler algorithm!")
       end
dispatchtest (generic function with 3 methods)

julia> dispatchtest(:Foo)
This is the generic dispatch. The algorithm is Foo

julia> dispatchtest(:Euler)
This is for the Euler algorithm!

关于julia - 带符号的通用调度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39314925/

10-11 06:53