How to delete a function?

As said by others:

  • If what you want is to make sure that the function name is not used before, or it does not exist, you can query with the function isdefined, or easier with the macro @isdefined (e.g. @isdefined foo to query if there is anything called foo in the current module`.
  • If you want to delete a function (or whatever other type of object’s) name, unfortunately you can’t. (There are other useful FAQs in the same page.)

The nearest thing to Matlab’s workspaces in Julia are modules. It is possible to switch between modules in the REPL, which is the closest that you’ll get to clear all in Matlab (without actually deleting anything), but it’s better to adapt your workflows so that you don’t feel the need of “deleting variables”, which is unnatural in Julia.

Since you are asking several questions related to transitioning from Matlab to Julia, let me recommend you to spend some time reading some of the many resources that the community has being producing for such situations. There is a thread from a few year ago where they started to comment on this:

And some other resources that might be useful too (you’ll find many more with any search engine):

https://en.wikibooks.org/wiki/Julia_for_MATLAB_Users

4 Likes