Reputation: 1097
The question may apply for other languages, too.
If I use a built-in function name as a variable name, I can restore the function by doing:
all = 123
all = Base.all
But If I define, for example, a custom function sum() and then I do,
sum = Base.sum
I got an error saying "invalid redefinition of constant sum"
Is there a way to restore a built-in function if I over-wrote it? Or is that impossible by design?
Upvotes: 4
Views: 464
Reputation: 4181
For this example, you could just redefine sum
as Base.sum
:
sum(x) = Base.sum(x)
Is that what you would like?
NB. this may not "overwrite" your definition of sum. If it uses type parameters (e.g. sum(x::Vector)
it may still be dispatched in preference to the general sum(x)
, in which case you would need to repeat the above for those specific methods.
Upvotes: 2
Reputation: 1750
If this is simply a problem for you when you are working in the REPL, and you don't mind losing all your other definitions, you could do workspace()
to reset Main
.
Upvotes: 1