Trying to append a tree structure into a list. In Erlang I would use the ++ operator for appending but I keep getting syntax errors when doing this in Prolog.
I will include my error code, its all about the appending of lists that I think is missing.
tree2list(leaf(X),L++[X]).
tree2list(branch(Branch1,Branch2),L):-
tree2List(B1,L1),
tree2List(B2,L2),
L++L1++L2.
Any ideas how to solve my appending issue?
Sure, use difference lists:
But your tree doesn’t seem to have empty branches. Add them thus: