Wolfram Computation Meets Knowledge

Wolfram Language & System Documentation Center Wolfram Language Home Page »

TreeExpression

TreeExpression[tree]

gives an expression from the structure of the Tree object tree.

TreeExpression[tree,struct]

gives an expression with data and subtrees of tree interpreted as specified by struct.

Details and Options

Examples

open allclose all

Basic Examples  (4)

Construct an expression from the structure of a tree:

Include heads:

Specify the structure to use:

Construct symbolic XML from a tree:

Construct a held expression from a tree:

Construct nested associations from a tree:

Scope  (14)

Arbitrary Expressions  (6)

"HeadTrees"  (1)

If TreeQ[data] gives False, then TreeExpression[Tree[data,{tree1,tree2,…}],"HeadTrees"] gives an expression with head data and with arguments given by the TreeExpression[treei,"HeadTrees"]:

If TreeQ[data] gives True, then TreeExpression[Tree[data,{tree1,tree2,…}],"HeadTrees"] gives an expression with head TreeExpression[data,"HeadTrees"] rather than data:

Include heads:

TreeExpression[Tree[data,None],"HeadTrees"] gives data:

"Heads"  (1)

TreeExpression[Tree[data,{tree1,tree2,…}],"Heads"] gives an expression with head data and with arguments given by the TreeExpression[treei,"Heads"]:

Include heads:

TreeExpression[Tree[data,None],"Heads"] gives data:

"Subexpressions"  (1)

TreeExpression[Tree[…,{tree1,tree2,…}],"Subexpressions"] gives an expression with arguments given by the TreeExpression[treei,"Subexpressions"]:

Include heads:

TreeExpression[Tree[data,None],"Subexpressions"] gives data:

"Atoms"  (1)

TreeExpression[Tree[…,{tree1,tree2,…}],"Atoms"] gives an expression with arguments given by the TreeExpression[treei,"Atoms"]:

Include heads:

TreeExpression[Tree[data,None],"Atoms"] gives data:

Null  (1)

TreeExpression[Tree[…,{tree1,tree2,…}],Null] gives an expression with arguments given by the TreeExpression[treei,Null]:

Include heads:

TreeExpression[Tree[…,None],Null] gives Null:

None  (1)

TreeExpression[Tree[data,…],None] gives data:

Common Expressions  (1)

"XML"  (1)

Construct symbolic XML from a tree:

Nested Lists and Associations  (3)

"List"  (1)

Construct nested lists from a tree:

"Association"  (1)

Construct nested associations from a tree:

"Dataset"  (1)

Construct a dataset from a tree:

Nested Rules  (4)

"Rules"  (1)

Construct nested rules from a tree:

"JSON"  (1)

Construct JSON rules from a tree:

"RawJSON"  (1)

Construct JSON associations from a tree:

"FileSystem"  (1)

Construct a nested association with file names as keys from a tree:

Options  (2)

Heads  (2)

With the default option setting HeadsFalse, heads of expressions are not included as part of any level:

With HeadsTrue, heads are included just like other elements of expressions:

Structures for arbitrary expressions do not include heads by default:

Include heads:

Properties & Relations  (7)

Transform a tree into an expression:

Transform the resulting expression back into a tree:

Construct a tree from an expression:

Get back the original expression:

Construct a tree from the heads in an expression:

Use TreeFold to insert a parent node above each subtree:

This corresponds to mapping on the arguments in an expression:

Map maps on the arguments in an expression by default:

Construct a tree from the atoms in an expression:

Use TreeFold to insert a sibling node before each subtree:

This corresponds to mapping on the subexpressions in an expression:

Map maps on the subexpressions in an expression with HeadsTrue:

Construct a tree from the heads in an expression:

TreeMap maps on the data of subtrees in a tree:

This corresponds to mapping on the heads and leaves in an expression:

Map can map on the heads and leaves directly:

Construct a tree from the atoms in an expression:

TreeMap can map on the data of just the leaves in a tree:

This corresponds to mapping on the atoms in an expression:

Map can map on the atoms in an expression directly:

The expression constructed by TreeExpression is evaluated before being returned:

Held structures wrap the expression in HoldComplete to prevent evaluation:

Wolfram Research (2021), TreeExpression, Wolfram Language function, https://reference.wolfram.com/language/ref/TreeExpression.html (updated 2022).

Text

Wolfram Research (2021), TreeExpression, Wolfram Language function, https://reference.wolfram.com/language/ref/TreeExpression.html (updated 2022).

CMS

Wolfram Language. 2021. "TreeExpression." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/TreeExpression.html.

APA

Wolfram Language. (2021). TreeExpression. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TreeExpression.html

BibTeX

@misc{reference.wolfram_2024_treeexpression, author="Wolfram Research", title="{TreeExpression}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/TreeExpression.html}", note=[Accessed: 18-May-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_treeexpression, organization={Wolfram Research}, title={TreeExpression}, year={2022}, url={https://reference.wolfram.com/language/ref/TreeExpression.html}, note=[Accessed: 18-May-2024 ]}

Top