I'm not entirely sure of what you are asking for, but here is a simple (and naive, it will probably not work on more complicated cases) way to convert the output of DownValues
to a format similar to the output of Definition
:
definitions[symb_Symbol] := DownValues @ symb /. {
Verbatim[RuleDelayed][a_, b_] :> Hold[SetDelayed[a, b]]
} /. Verbatim[HoldPattern][args__] :> args
for example:
foo[x_] := x + 2;
foo[x_List] := x + 3
foo[x_, y_] := x + y
definitions @ foo
produces
{Hold[foo[x_List] := x + 3], Hold[foo[x_] := x + 2], Hold[foo[x_, y_] := x + y]}
To also remove the Hold
from the output you can use this other version:
definitions[symb_Symbol] := DownValues @ symb /. {
Verbatim[RuleDelayed][a_, b_] :> Hold[SetDelayed[a, b]]
} /. Verbatim[HoldPattern][args__] :> args /. {
Hold[args__] :> Defer[args]
}
Replacing DownValues
with Definitions
from GeneralUtilities
should moreover generalise the function to also capture UpValues
, OwnValues
etc.
Definition
and similar functionsPrint
the definitions associated to the symbol, instead of giving them as output. Are you asking for a function that takes a symbol as input and gives the definitions as output? $\endgroup$