Wolfram Research

DefinitionData

Contributed by: Richard Hennigan (Wolfram Research)

Source Notebook

Store full definitions for a symbol in a compact object

ResourceFunction["DefinitionData"][symbol]

returns a definition object for symbol and all its dependencies.

ResourceFunction["DefinitionData"][][property]

returns the definition information specified by property.

Details and Options

In ResourceFunction["DefinitionData"][][property], possible values for property include:
"Name" the fully qualified name of the symbol
"Definitions" an Association containing full definition information
"Symbols" a list of all the contained symbols, each wrapped in HoldForm
"Names" a list of fully qualified symbol names
"Size" the full size of the definition data in bytes
"Contexts" a list of all contexts for the defined symbols
"DefinitionList" returns a Language`DefinitionList of the definition data
Get[ResourceFunction["DefinitionData"][]] will restore all the contained definitions.
Information[ResourceFunction["DefinitionData"][]] provides a summary of some properties.

Examples

Basic Examples

Get all needed definitions for f, which depends on the function g:

In[1]:=
g[x_] := x^3
In[2]:=
f[x_] := g[x^2]
In[3]:=
data = ResourceFunction["DefinitionData"][f]
Out[3]=

View information about the definitions:

In[4]:=
Information[data]
Out[4]=

Using Get can restore cleared symbols:

In[5]:=
ClearAll[f, g];
f[5]
Out[6]=
In[7]:=
Get[data]
Out[7]=
In[8]:=
f[5]
Out[8]=

Applications

Store definitions from a package as an object that can be stored in notebooks:

In[9]:=
Get["ExampleData/Collatz.m"];
data = ResourceFunction["DefinitionData"][Collatz`Collatz]
Out[10]=

View the definitions:

In[11]:=
data["Definitions"]
Out[11]=
In[12]:=
ClearAll[Collatz`Collatz];

This is now equivalent to loading the original package:

In[13]:=
Get[data]
Out[13]=

The definition is loaded:

In[14]:=
Definition[Collatz`Collatz]
Out[14]=
In[15]:=
Collatz`Collatz[47]
Out[15]=

Properties and Relations

Get a list of available properties:

In[16]:=
ResourceFunction["DefinitionData"][
Association[
  "Name" -> "Global`DefinitionData", "Definitions" -> ByteArray[CompressedData["
1:eJwBkAhv9yFib1JiAQAAAIMIAAA4Qzp4nO1a724bNxLP6o8tya7dBCiM4g64
Rb7ch54CtP0WoChkOXZzF8d/qPQ+FEVFSVx7m13udsm1rXz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CsHspHC/Q6iWLxH2kF/bC3t2zwtxLzbxaRzBo9NUF
6T4kUcD1N2P13a8YFlZeoIC5G50QmXyGTu44Q2ftyfqOP8zH8oRNyw3fFtB+
BdG+0LYnROCMnXXrPEiFndsjH4Ju2LQsARtsWRdQbSCZts5msws7xfZJQuB3
YmP64D0zRGYAux7t8+iWJMPG8D9LLdF+dkPoJqbYHCVNRVA7FWPoF0e9+I5+
716Jo1wAyQD4upHn8mvi+sANVmeuT+Xzl/SzzwVgQiIO/9Zz1YdxnHDICq6X
RKFLn7gjIIViS9zupwkR+MuvMYd/4BdThZCLg1s8ZwUTWCn0qVjsyYcQ+xBi
H0LsHYeYcZ0waFYjbLVTOMdyK7FwAKyVG+ouQ+wkAquJ0972EYllGbwrGIsD
JXERVk4eNtaWwdZ3Fbe/H0E2x2nAF0o16y47bPssrp6xl6vImfaqcV8wGQRB
rk8fLb1IWaugWX4l86S+bbfRl//RrnrtsJZENTcXf60VpUrYR8sal7UkWdoB
9WvlsZGXJac4ONio5BQTZS+agJbiIKON+Dy7xrrEt9nZddntN8tjnmr/jxwP
un7UuPsBen3UePoVajx+PNwtO+tjkPgYh34wR/tIauYiTJl7nhStIusKIsCi
KBEnWCcJnr8gNyRIHsjPb1+X3A6hPbtKxLFuldKTn39//V8WMr9iv1I2gA==

"]]]]["Properties"]
Out[16]=

See what symbols are contained:

In[17]:=
ResourceFunction["DefinitionData"][
Association[
  "Name" -> "Global`DefinitionData", "Definitions" -> ByteArray[CompressedData["
1:eJwBkAhv9yFib1JiAQAAAIMIAAA4Qzp4nO1a724bNxLP6o8tya7dBCiM4g64
Rb7ch54CtP0WoChkOXZzF8d/qPQ+FEVFSVx7m13udsm1rXzqS/QV+jx9hnuA
e4W7IZe7y6W4sqQ01xwQwYi0y+FwZjjzmxkyg24ffXISRBMcjI+I51Of+xE9
whwPtvqsi9LJtzhICfN6rPXCZ9xrsJ3LNCBHJMBzMvMctvNNFMzOMeckoZ4D
L+zsYGD/H2QuueXUDdYS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JQuB3
YmP64D0zRGYAux7t8+iWJMPG8D9LLdF+dkPoJqbYHCVNRVA7FWPoF0e9+I5+
716Jo1wAyQD4upHn8mvi+sANVmeuT+Xzl/SzzwVgQiIO/9Zz1YdxnHDICq6X
RKFLn7gjIIViS9zupwkR+MuvMYd/4BdThZCLg1s8ZwUTWCn0qVjsyYcQ+xBi
H0LsHYeYcZ0waFYjbLVTOMdyK7FwAKyVG+ouQ+wkAquJ0972EYllGbwrGIsD
JXERVk4eNtaWwdZ3Fbe/H0E2x2nAF0o16y47bPssrp6xl6vImfaqcV8wGQRB
rk8fLb1IWaugWX4l86S+bbfRl//RrnrtsJZENTcXf60VpUrYR8sal7UkWdoB
9WvlsZGXJac4ONio5BQTZS+agJbiIKON+Dy7xrrEt9nZddntN8tjnmr/jxwP
un7UuPsBen3UePoVajx+PNwtO+tjkPgYh34wR/tIauYiTJl7nhStIusKIsCi
KBEnWCcJnr8gNyRIHsjPb1+X3A6hPbtKxLFuldKTn39//V8WMr9iv1I2gA==

"]]]]["Names"]
Out[17]=

Use a list of properties to return an Association:

In[18]:=
ResourceFunction["DefinitionData"][
Association[
  "Name" -> "Global`DefinitionData", "Definitions" -> ByteArray[CompressedData["
1:eJwBkAhv9yFib1JiAQAAAIMIAAA4Qzp4nO1a724bNxLP6o8tya7dBCiM4g64
Rb7ch54CtP0WoChkOXZzF8d/qPQ+FEVFSVx7m13udsm1rXzqS/QV+jx9hnuA
e4W7IZe7y6W4sqQ01xwQwYi0y+FwZjjzmxkyg24ffXISRBMcjI+I51Of+xE9
whwPtvqsi9LJtzhICfN6rPXCZ9xrsJ3LNCBHJMBzMvMctvNNFMzOMeckoZ4D
L+zsYGD/H2QuueXUDdYSvOB7W71i+2pynEQxSfjce8DahwGmr3WiXUV0I5hZ
KWrZGHM31ibnh3rn2RI+2KiT2Qi1XuKQoN7Z5Ecy5aN5TNBOOZ2hthhmaBvN
w0kUMNRC/huCOsOIcnLHGdorid/O5KWQmih7BtF93DWrdtQys012uWI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d/4BdThZCLg1s8ZwUTWCn0qVjsyYcQ+xBi
H0LsHYeYcZ0waFYjbLVTOMdyK7FwAKyVG+ouQ+wkAquJ0972EYllGbwrGIsD
JXERVk4eNtaWwdZ3Fbe/H0E2x2nAF0o16y47bPssrp6xl6vImfaqcV8wGQRB
rk8fLb1IWaugWX4l86S+bbfRl//RrnrtsJZENTcXf60VpUrYR8sal7UkWdoB
9WvlsZGXJac4ONio5BQTZS+agJbiIKON+Dy7xrrEt9nZddntN8tjnmr/jxwP
un7UuPsBen3UePoVajx+PNwtO+tjkPgYh34wR/tIauYiTJl7nhStIusKIsCi
KBEnWCcJnr8gNyRIHsjPb1+X3A6hPbtKxLFuldKTn39//V8WMr9iv1I2gA==

"]]]][{"Name", "Size", "Contexts"}]
Out[18]=

The InputForm of DefinitionData serializes definitions to protect contexts and initialization states of values:

In[19]:=
ResourceFunction["DefinitionData"][
Association[
  "Name" -> "Global`f", "Definitions" -> ByteArray[{56, 67, 58, 120, 156, 115, 100, 210, 13, 230, 112, 207, 201, 79, 74, 204, 73, 72, 115, 100, 212, 45, 230, 114, 201, 47, 207, 11, 75, 204, 41, 77, 45, 78, 99, 44, 102,
      241, 201, 44, 46, 73, 99, 42, 230, 14, 42, 205, 73, 117, 73, 205, 73, 172, 76, 77, 1, 10, 115, 123, 228, 231, 164, 4, 36, 150,
      148, 164, 22, 229, 1, 185, 112, 3, 128, 42, 217, 161, 194, 112, 193, 138, 52, 134, 98, 86, 167, 156, 196, 188, 108, 36, 149, 233,
      64, 149, 172, 1, 249, 229, 169, 69, 8, 117, 206, 72, 78, 73, 167, 212, 41, 233, 4, 156, 130, 197, 122, 102, 0, 131, 144, 89, 77}]]] // InputForm
Out[19]=

Use FullForm to see the actual expression structure:

In[20]:=
ResourceFunction["DefinitionData"][
Association[
  "Name" -> "Global`f", "Definitions" -> ByteArray[{56, 67, 58, 120, 156, 115, 100, 210, 13, 230, 112, 207, 201, 79, 74, 204, 73, 72, 115, 100, 212, 45, 230, 114, 201, 47, 207, 11, 75, 204, 41, 77, 45, 78, 99, 44, 102,
      241, 201, 44, 46, 73, 99, 42, 230, 14, 42, 205, 73, 117, 73, 205, 73, 172, 76, 77, 1, 10, 115, 123, 228, 231, 164, 4, 36, 150,
      148, 164, 22, 229, 1, 185, 112, 3, 128, 42, 217, 161, 194, 112, 193, 138, 52, 134, 98, 86, 167, 156, 196, 188, 108, 36, 149, 233,
      64, 149, 172, 1, 249, 229, 169, 69, 8, 117, 206, 72, 78, 73, 167, 212, 41, 233, 4, 156, 130, 197, 122, 102, 0, 131, 144, 89, 77}]]] // FullForm
Out[20]=

When writing DefinitionData to a file as InputForm via Put, CloudPut, Export, etc, original contexts will be preserved in binary form:

In[21]:=
$Context = "MyContext`";
In[22]:=
g1[x_] := x^3
In[23]:=
f1[x_] := g1[x^2]
In[24]:=
data = ResourceFunction["DefinitionData"][f1]
Out[24]=
In[25]:=
Put[data, "file.wl"];
FilePrint["file.wl"]

Changing $Context or $ContextPath will not affect which contexts the contained symbols are created in:

In[26]:=
$Context = "Global`";
In[27]:=
Remove[MyContext`f1, MyContext`f2];
In[28]:=
Get["file.wl"]
Out[28]=

Load the definitions:

In[29]:=
Get[%]
Out[29]=

The symbols are redefined in their original contexts:

In[30]:=
MyContext`f1[5]
Out[30]=

Possible Issues

Some contexts (such as System`) are excluded when including definitions:

In[31]:=
a := {b, Table};
b := {MyContext`c, CloudObject};
MyContext`c := 1;
In[32]:=
ResourceFunction["DefinitionData"][a]
Out[32]=
In[33]:=
%["Names"]
Out[33]=

Resource History

See Also