Research Article

Behaviour Preservation across Code Versions in Erlang

Listing 16

orddict_old.erl.
(1) -spec from_list(List) -> Orddict when
(2)   List:: [Key:: term(), Value:: term()],
(3)   Orddict:: orddict().
(4)
(5) from_list(Pairs) ->
(6)   lists:foldl(
(7)    fun (K,V, D) -> store(K, V, D) end, [], Pairs).
(8)
(9) -spec store(Key, Value, Orddict1) -> Orddict2 when
(10)    Key:: term(),
(11)    Value:: term(),
(12)    Orddict1:: orddict(),
(13)    Orddict2:: orddict().
(14)
(15) store(Key, New, [K,_=EDict]) when Key < K ->
(16)   [Key,New,EDict];
(17) store(Key, New, [K,_=EDict]) when Key > K ->
(18)   [Estore(Key, New, Dict)];
(19) store(Key, New, [_K,_OldDict]) -> % Key == K
(20)   [Key,NewDict];
(21) store(Key, New, []) -> [Key,New].