mybalance(L) :- L = []. mybalance(L) :- append(L2,[C],L), C \= '<', C \= '>', mybalance(L2).