Posted to tcl by Florentis at Thu Dec 03 10:40:07 GMT 2026view raw
- # v18m: jumps within a recursive type, T(<0><2><1>v)
- # <&> follows a recursive edge (a path from the type to itself, calculated once
- # within the type profile: typeprofile edges). The content of a jump is
- # read along the edge: a name refers to one of its fields or variants
- # (optional), while each collection takes an index, a slice, a tuple, or a key.
- # <>: the only edge without a collection; <*>: the children; <**>: the node
- # and its descendants, in pre-order. Jumps resolve into standard steps
- # according to the typereads and writeswhile <*> and <**> are interpreted
- # as read operations.
-
- # generic Tree
- type def arbre {
- {double}v;
- {list.arbre}fils
- }
-
- # binary Tree
- type def bin {
- "nil" | {
- {double}v;
- {bin}g;
- {bin}d
- }noeud
- }
-
- # "Linked" list
- type def liste {
- "fin" | {
- {double}v;
- {liste}suite
- }m
- }
-
- # recursive by dict
- type def rose {
- {int}v;
- {dict.rose}enfants
- };
-
- # ternary Tree
- type def tri {
- {double}v;
- {list(3).tri}fils
- }
-
- # Forest
- type def foret list.arbre
-
- set T [type cast arbre {1.0 {{2.0 {}} {3.0 {{4.0 {}} {5.0 {}}}} {6.0 {}}}}]
- set B [type cast bin {1.0 {2.0 nil {3.0 nil nil}} {4.0 nil nil}}]
- set L [type cast liste {1.0 {2.0 {3.0 fin}}}]
- set R [type cast rose {1 {a {2 {}} b {3 {c {4 {}}}}}}]
- set F [type cast foret {{1.0 {}} {2.0 {{3.0 {}}}}}]
-
- # Reading :
-
- set T(<1><0>v) ;# 4.0 (= child.1.child.0.v) Jump with list indices
- set T(<child.1><1>v) ;# 5.0 named edge, then its indice
- set B(<g><d>v) ;# 3.0 (= node.g.node.d.v)
- set L(<><>v) ;# 3.0 <> : the only edge collection
- set R(<b><c>v) ;# 4 Jump with keys of dict
- set T(<(0,2)>v) ;# 2.0 6.0 tuple in a jump (2 results)
- set T(<*>v) ;# 2.0 3.0 6.0 : The children
- $T(<**>v) ;# 1.0 2.0 & 6.0 : All the tree, in preorder
-
- # Writing :
-
- set T(<1><0>v) 40.0
- set B(<g><d>v) 30.0
- set L(<><>v) 9.5
Add a comment