wolfram mathematica - How to get all definitions associated with other symbols? -
how definitions symbol associated other symbols tagset
, tagsetdelayed
, upset
or upsetdelayed
?
for example, if 1 has defined
area[square] ^= s^2 area[cube] ^= 6*s^2
how obtain these definitions, not knowing names square
, cube
knowing name area
?
i have found upvalues
not return definitions makeboxes
, n
since stored in formatvalues
, nvalues
correspondingly:
in[1]:= rotate /: makeboxes[expr_rotate, "standardform"] := x upvalues[rotate] formatvalues[rotate] out[2]= {} out[3]= {holdpattern[makeboxes[expr_rotate, "standardform"]] :> x} in[4]:= pi /: n[pi] = 3.14 upvalues[pi] nvalues[pi] out[4]= 3.14 out[5]= {} out[6]= {holdpattern[n[pi, {machineprecision, machineprecision}]] :> 3.14}
in way instead of upvalues
should use combination of upvalues
, formatvalues
, nvalues
.
when trying output list of formatvalues
1 can face problems makeboxes
since formatvalues
gives definitions makeboxes
are further processed makeboxes
on creating output frontend. problem can solved switching formattype
temporarily outputform
or converting these definitions strings.
in[1]:= setoptions[$output,formattype->outputform]; formatvalues[dialognotebook] out[2]= {holdpattern[makeboxes[boxform`apat$:holdpattern[dialognotebook[___]], boxform`fpat$_]] :> boxform`boxformautoload[makeboxes, boxform`apat$, boxform`fpat$, typeset`cellnotebook`, {{cellgroup, _}, {documentnotebook, _}, {palettenotebook, _}, {dialognotebook, _}, {expressioncell, _}, {text, _}, {textcell, _}, {cell, holdpattern[makeexpression[_cell, _]]}, {notebook, holdpattern[makeexpression[_notebook, _]]}}]} in[1]:= tostring@formatvalues[dialognotebook] out[1]= {holdpattern[makeboxes[boxform`apat$:holdpattern[dialognotebook[___]], boxform`fpat$_]] :> boxform`boxformautoload[makeboxes, boxform`apat$, boxform`fpat$, typeset`cellnotebook`, {{cellgroup, _}, {documentnotebook, _}, {palettenotebook, _}, {dialognotebook, _}, {expressioncell, _}, {text, _}, {textcell, _}, {cell, holdpattern[makeexpression[_cell, _]]}, {notebook, holdpattern[makeexpression[_notebook, _]]}}]}
attempting address alexey's concerns howard's answer, came this:
cases[ upvalues @@@ makeexpression /@ names["global`*"], holdpattern[_@_area :> _], {2} ]
in response updated requirements, here advanced version:
setattributes[othervalues, holdfirst] othervalues[sym_] := with[{names = makeexpression /@ names["global`*"]}, join[ cases[upvalues @@@ names, holdpattern[_@_sym :> _], {2}], cases[nvalues @@@ names, holdpattern[_@n[sym, ___] :> _], {2}], select[join @@ formatvalues @@@ names, ! freeq[#, holdpattern@sym] &] ] ]
Comments
Post a Comment