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
- TreeExpression can construct lists, arrays, rules, XML and arbitrary expressions from Tree objects as specified.
- Possible forms for struct for arbitrary expressions include: »
-
"HeadTrees" trees corresponding to heads of subexpressions of the expression by level "Heads" heads of subexpressions of the expression by level "Subexpressions" subexpressions of the expression by level "Atoms" atomic subexpressions of the expression at level -1 Null subexpressions of the expression by level with no data None the expression itself - Options of TreeExpression include:
-
Heads include heads of expressions and their parts as subtrees - Possible structures for the expression f[a,b][g[1,2],x,y] include:
- Versions of these structures with the option setting HeadsTrue include: »
- Held forms for struct for arbitrary expressions include:
-
"HeldHeadTrees" trees corresponding to held heads of subexpressions of the expression by level "HeldHeads" held heads of subexpressions of the expression by level "HeldSubexpressions" held subexpressions of the expression by level "HeldAtoms" held atomic subexpressions of the expression at level -1 - Possible forms for struct for common types of expressions include:
-
"XML" tags, attributes and elements of an XML object - Possible forms for struct for nested lists and associations include: »
-
"List" elements of nested lists "Association" elements of nested associations "Dataset" headers and data of a dataset - Possible forms for struct for nested rules include: »
-
"Rules" left-hand sides and leaves of nested rules "JSON" names and values of a JSON object, using names as data "RawJSON" names and values of a JSON object, using names as keys "FileSystem" directories and files in a file system
Examples
open allclose allBasic Examples (4)
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:
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"]:
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"]:
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"]:
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]:
TreeExpression[Tree[…,None],Null] gives Null:
None (1)
TreeExpression[Tree[data,…],None] gives data:
Nested Lists and Associations (3)
Options (2)
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:
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