Posted to tcl by Florentis at Thu Dec 03 10:40:07 GMT 2026view raw

  1. # v18m: jumps within a recursive type, T(<0><2><1>v)
  2. # <&> follows a recursive edge (a path from the type to itself, calculated once
  3. # within the type profile: typeprofile ’ edges). The content of a jump is
  4. # read along the edge: a name refers to one of its fields or variants
  5. # (optional), while each collection takes an index, a slice, a tuple, or a key.
  6. # <>: the only edge without a collection; <*>: the children; <**>: the node
  7. # and its descendants, in pre-order. Jumps resolve into standard steps
  8. # according to the typereads and writeswhile <*> and <**> are interpreted
  9. # as read operations.
  10.  
  11. # generic Tree
  12. type def arbre {
  13. {double}v;
  14. {list.arbre}fils
  15. }
  16.  
  17. # binary Tree
  18. type def bin {
  19. "nil" | {
  20. {double}v;
  21. {bin}g;
  22. {bin}d
  23. }noeud
  24. }
  25.  
  26. # "Linked" list
  27. type def liste {
  28. "fin" | {
  29. {double}v;
  30. {liste}suite
  31. }m
  32. }
  33.  
  34. # recursive by dict
  35. type def rose {
  36. {int}v;
  37. {dict.rose}enfants
  38. };
  39.  
  40. # ternary Tree
  41. type def tri {
  42. {double}v;
  43. {list(3).tri}fils
  44. }
  45.  
  46. # Forest
  47. type def foret list.arbre
  48.  
  49. set T [type cast arbre {1.0 {{2.0 {}} {3.0 {{4.0 {}} {5.0 {}}}} {6.0 {}}}}]
  50. set B [type cast bin {1.0 {2.0 nil {3.0 nil nil}} {4.0 nil nil}}]
  51. set L [type cast liste {1.0 {2.0 {3.0 fin}}}]
  52. set R [type cast rose {1 {a {2 {}} b {3 {c {4 {}}}}}}]
  53. set F [type cast foret {{1.0 {}} {2.0 {{3.0 {}}}}}]
  54.  
  55. # Reading :
  56.  
  57. set T(<1><0>v) ;# ’ 4.0 (= child.1.child.0.v) Jump with list indices
  58. set T(<child.1><1>v) ;# ’ 5.0 named edge, then its indice
  59. set B(<g><d>v) ;# ’ 3.0 (= node.g.node.d.v)
  60. set L(<><>v) ;# ’ 3.0 <> : the only edge collection
  61. set R(<b><c>v) ;# ’ 4 Jump with keys of dict
  62. set T(<(0,2)>v) ;# ’ 2.0 6.0 tuple in a jump (2 results)
  63. set T(<*>v) ;# ’ 2.0 3.0 6.0 : The children
  64. $T(<**>v) ;# ’ 1.0 2.0 & 6.0 : All the tree, in preorder
  65.  
  66. # Writing :
  67.  
  68. set T(<1><0>v) 40.0
  69. set B(<g><d>v) 30.0
  70. set L(<><>v) 9.5

Add a comment

Please note that this site uses the meta tags nofollow,noindex for all pages that contain comments.
Items are closed for new comments after 1 week