[erlang-questions] orddict - is it an expected behavior?

Kostis Sagonas kostis@REDACTED
Tue Jan 12 13:58:10 CET 2016


On 01/12/2016 01:50 PM, Minin Maxim wrote:
> Hi All,
>
> is it an expected behavior?
>
> 1> orddict:merge(fun(_, _X, Y) -> Y end,  orddict:from_list([{1,a},{2,b}]), [{1,c},{1,f}]).
> [{1,c},{1,f},{2,b}]
>
> Here returns merge function an invalid orddict.
>
> I know, if the second argument is a valid orddict, all is fine:
>
> 2> orddict:merge(fun(_, _X, Y) -> Y end,  orddict:from_list([{1,a},{2,b}]), orddict:from_list([{1,c},{1,f}])).
> [{1,f},{2,b}]
>
> I would expect, that merge function either generates an exception or returns a proper orddict, but here is that not the case. Am I wrong?

Yes, you are.

If you violate the preconditions of a function (as expressed by the 
properties that are expected by its arguments), you cannot expect that 
its postcondition (its return) is what the documentation promises.

Kostis



More information about the erlang-questions mailing list