1
$\begingroup$

How do you see the code form of a command in Mathematica?

I know there is a command in Mathematica, "Unprotect[]", but how do you actually use this?

$\endgroup$
1
  • $\begingroup$ Do notice many of the built-in functions are just blackboxes, but definitions of functions that are not blackboxes can be checked with the tools above, particularly the PrintDefinitions. $\endgroup$
    – xzczd
    Commented Jul 10, 2020 at 4:13

1 Answer 1

3
$\begingroup$

Unprotect[] is there to remove the Protected attribute. This allows the definition of a command to be modified, but doesn't necessarily allow you to see the code that makes up the unmodified command. Protect helps to prevent accidental changes like +=3 redefining the + command. You can even Protect your own functions if you're worried about accidentally changing a definition.

If you want to read the Wolfram code, I have used:

Needs["GeneralUtilities`"]
PrintDefinitions[Charting`ScaledTicks]

to access some of the definitions. However, Mathematica is proprietary software. There are many functions where this won't work. For example, PrintDefinitions[NDSolve] shows a few options, but the actual code itself is a kernel function that cannot be read in this way. If you really want to read the code itself for any arbitrary function, I suspect the only way is to apply for a position at WRI.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.