How to remove a function in Julia REPL?

Viewed 3396

How do you remove a function you have created when working in the Julia REPL? Can this be done without restarting the session? This came up for me because I created a function with the wrong type input, then made it correctly, but couldn't get rid of the old one.

The FAQ at http://docs.julialang.org/en/release-0.4/manual/faq/ states:

Julia does not have an analog of MATLAB’s clear function; once a name is
defined in a Julia session (technically, in module Main), it is always present.
3 Answers

Assuming you have defined a function

xx(x) = 42

you can find the method with

m = @which xx(1)

and remove it with

Base.delete_method(m)

Note Base.delete_method(xx) won't work, i.e. you won't get rid of the new function (with name xx) like this. If you try, you'll still get:

julia> xx
xx (generic function with 0 methods)

=> The function name xx is still known, but the method you defined is gone. But for deleting a "function with the wrong type input" as you asked for, this would probably be the solution you want.

(Based on this thread.)

Related