5
$\begingroup$

I deleted the code of a function that I wrote. The function is still working fine but the code is no more available. How can I do to display the code of the function I have written ?

Edit: Thanks for your answers.

「??f」 works lovely well ! it is the best. DownValues[f] as well (but not UpValues, neither oeher **Values)

PrintDefinitions[f] as well, but requires GeneralUtilities...

$\endgroup$
  • 2
    $\begingroup$ Use ?? f or DownValues[f] (or possibly OwnValues[f], Upvalues[f], and/or SubValues[f] etc). The first will be easier to interpret, if you don't know how down-values work. $\endgroup$ – Michael E2 Oct 19 '16 at 12:12
  • 11
    $\begingroup$ The simplest thing to do is perhaps to call Needs["GeneralUtilities`"] and then PrintDefinitions[f]. This will create a separate notebook with a nicely formatted code of your function. You can then select the cells with code and right-click, then use Copy As Plain text, and copy to a new input cell, if you want to. $\endgroup$ – Leonid Shifrin Oct 19 '16 at 12:14
  • $\begingroup$ Another useful function is Language`ExtendedDefinition, which takes either the symbol or the symbol name as an argument, and returns *Values, Messages and Attributes. $\endgroup$ – Carl Woll Jan 23 '17 at 5:38
3
$\begingroup$

To remove this question from the Unanswered:

The simplest thing to do is perhaps to call Needs["GeneralUtilities`"] and then PrintDefinitions[f]. This will create a separate notebook with a nicely formatted code of your function. You can then select the cells with code and right-click, then use Copy As Plain text, and copy to a new input cell, if you want to. – Leonid Shifrin Oct 19 '16 at 12:14

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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