[erlang-questions] gb_trees, strange behaviour

Kostis Sagonas kostis@REDACTED
Fri Nov 5 18:52:45 CET 2010

Michal D. wrote:
> Hi again,
> I'm having a lot of problems starting out with Erlang. It appears to me that
> I can't update a specific key of a gb_tree, while the other ones work fine.
> Can anyone explain the following behaviour?
>> X = gb_trees:from_orddict([{trace,false},{limit,-1},{timeout,-1}]).
> {3,{limit,-1,{trace,false,nil,nil},{timeout,-1,nil,nil}}}
>> gb_trees:update(limit,true,X).
> {3,{limit,true,{trace,false,nil,nil},{timeout,-1,nil,nil}}}
>> gb_trees:update(timeout,true,X).
> {3,{limit,-1,{trace,false,nil,nil},{timeout,true,nil,nil}}}
>> gb_trees:update(trace,true,X).
> ** exception error: no function clause matching
>                     gb_trees:update_1(trace,true,nil)
>      in function  gb_trees:update_1/3
>      in call from gb_trees:update/3

The update calls that you think they work, work by fluke. The problem is 
that even though you may think you have created a gb tree, but in fact 
you have not.

The problem lies in your first call:

   X = gb_trees:from_orddict([{trace,false},{limit,-1},{timeout,-1}]).

You promised you will supply an orddict, but in fact you have not.

   X = 

instead and things will work as expected.


More information about the erlang-questions mailing list