also why not use OOP?
type
Node = ref object of RootObj
BinaryOpr = ref object of Node
a, b: Node
UnaryOpr = ref object of Node
a: Node
Variable = ref object of Node
value: string
Value = ref object of Node
value: int
method traverse(n: Node) {.base} = discard
method traverse(n: Variable) = echo n.value
method traverse(n: Value) = echo n.value
method traverse(n: BinaryOpr) =
traverse n.a
traverse n.b
method traverse(n: UnaryOpr) =
traverse n.a
traverse BinaryOpr(
a: UnaryOpr(a: Variable(value: "hello")),
b: BinaryOpr(
a: Variable(value: "two"),
b: Value(value: 10)))
Run
- Sum types, 2024 variant ASVI
- Sum types, 2024 variant mildred
- Sum types, 2024 variant Araq
- Sum types, 2024 variant treeform
- Sum types, 2024 variant Araq
- Sum types, 2024 variant treeform
- Sum types, 2024 variant didlybom
- Sum types, 2024 variant xigoi
- Sum types, 2024 variant blackmius
- Sum types, 2024 variant ElegantBeef
- Sum types, 2024 variant blackmius
- Sum types, 2024 variant ElegantBeef
- Sum types, 2024 variant Araq
- Sum types, 2024 variant bajith
- Sum types, 2024 variant Araq
- Sum types, 2024 variant bajith
- Sum types, 2024 variant bajith
- Sum types, 2024 variant TKD
- Sum types, 2024 variant walkr
- Sum types, 2024 variant ingo
- Sum types, 2024 variant Nerve
