Research Article
Behaviour Preservation across Code Versions in Erlang
(1) -spec from_list(List) -> Orddict when | (2) List:: [Key:: term(), Value:: term()], | (3) Orddict:: orddict(). | (4) | (5) from_list([]) -> []; | (6) from_list([_,_]=Pair) -> Pair; | (7) from_list(Pairs) -> | (8) lists:ukeysort(1, reverse_pairs(Pairs, [])) % RIGHT | (9) lists:ukeysort(1, Pairs). % WRONG | (10) | (11) % ukeysort(N, TupleList1) -> TupleList2 | (12) % Returns a list containing the sorted elements of | (13) % list TupleList1 where all except the first tuple of | (14) % the tuples comparing equal have been deleted. | (15) % Sorting is performed on the Nth element of the tuple | (16) | (17) reverse_pairs([_,_=H∣T], Acc) -> | (18) reverse_pairs(T, [H∣Acc]); | (19) reverse_pairs([], Acc) -> Acc. |
|