fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 17: Create a Tree data structure
Idiom # 17: Create a Tree data structure
See
programming-idioms.org
:
Code
node(T type, val T, children Sequence (node T)) is
What are effects?
Running Example
node(T type, val T, children Sequence (node T)) is redef as_string => (as_strings 0).as_string "\n" as_strings(d i32) => ["+-" + $val] ++ (children.flat_map String (c->c.as_strings d+1)).map s->"| $s" feuille(val String) => node val (list (node String)).type.empty t := node "C" [feuille "C++", feuille "C#" , feuille "Go" , node "Java" [feuille "Scala", feuille "Kotlin"], node "Perl" [feuille "Ruby", feuille "Raku"], node "Python" [feuille "Julia", feuille "Nim" ] ] say t
What are effects?
last changed: 2024-07-01
next: Idiom # 18: Depth-first traversing of a tree