Deleting methods in julia

Hi all,

I am a relative newcomer to this version of Julia, so sorry for the (maybe) obvious question.

I have the problem, that I define multiple methods of a function in an interactive session (IJulia to be precise) in Julia v1.0.0 and I would like to delete some of those methods.

Is there any way to do that without restarting the session (or the kernel in this case)?

Thanks,
Maxi

2 Likes
julia> f(x::Integer) = 2
f (generic function with 1 method)

julia> f(x::Int) = 3
f (generic function with 2 methods)

julia> f(1)
3

julia> m = @which f(1)
f(x::Int64) in Main at REPL[2]:1

julia> typeof(m)
Method

julia> Base.delete_method(m)

julia> f(1)
2
30 Likes

Oh, great.

Thank you very much!

However, consider using Revise which uses this to automatically keep your REPL session up to date with your code on disk.

7 Likes

Is it possible to delete a type in a similar way?

2 Likes

Not really important, but the name seems a little un-idiomatic: delete_method(::Method). Why isn’t it just delete(::Method) or delete!(::Method)?

2 Likes

Not right now.

1 Like

Internal names—which this is since it’s not exported—often have underscores and longer more specific names.

3 Likes