Obviously, Plus[a,b]
is given by Mathematica but say I have a package and I want to name a function Plus[a,b]
. How can I go about making a new function without overwriting the original function Plus[a,b]
given from System.
I figured it might be something like this:
BeginPackage["Test`"]
Test`Plus::usage = "Plus[a_,b_] gives..."
(* function defs *)
Test`Plus[a_,b_] := ...
EndPackage[]
Or maybe it has something to do with Unprotect[]
? Ideally, I could still type in Plus[a,b]
and make use of the system function but I could also type in
Test`Plus[a,b]
to make use of the new Plus function from the package. Thanks
EDIT: in response to Marius Ladegård Meyer Is this what you are suggesting I do?
BeginPackage["Test`"]
Plus::usage = "asdf"
Begin["`Private`"]
Plus[a_,b_] := adfasf
End[]
EndPackage[]
And then I can use Test`Plus?
Begin/End
andBeginPackage/EndPackage
are the way to go here. UsingUnprotect
on such a central function asPlus
is an extremely bad idea, since it will modify a huge number of other (behind the scenes) Mathematica functions. $\endgroup$Begin["`Private`"]
or something? $\endgroup$Plus
. $\endgroup$