[mercury-users] challenge
Peter Schachte
pets at cs.mu.OZ.AU
Mon Sep 28 11:52:27 AEST 1998
Hi Gustavo,
Thanks for your solution. What I was looking for, though, was
something that would produce the same result whatever the shapes of
the trees. If you have
tree_to_list(empty, []).
tree_to_list(tree(L,N,R), List) :-
tree_to_list(L, Llist),
tree_to_list(R, Rlist),
append(Llist, [N|Rlist], List).
then this is a specification for what I want to get
collect_pairs(T1, T2, L) :-
tree_to_list(T1, L1),
tree_to_list(T2, L2),
zip(L1, L2, L).
zip([], _, []).
zip(_, [], []).
zip([E1|L1], [E2|L2], [E1-E2|L]) :-
zip(L1, L2, L).
except that I wanted to avoid the calls to tree_to_list, and still not
care about the shapes of the trees. As you've shown, one can produce
a verison that works when the trees are isomorphic. It's also not
hard to produce a version that only calls tree_to_list for one tree,
and then folds zip together with the other call to tree_to_list.
However, what I don't see how to do is to avoid *both* calls to
tree_to_list and still not require isomorphic trees.
--
Peter Schachte | There is something fascinating about
mailto:pets at cs.mu.OZ.AU | science. One gets such wholesale returns of
http://www.cs.mu.oz.au/~pets/ | conjecture out of such a trifling investment
PGP: finger pets at 128.250.37.3 | of fact. -- Mark Twain
More information about the users
mailing list