[erlang-questions] wierd outome on my match method

Roelof Wobben r.wobben@REDACTED
Sat Jan 31 15:11:57 CET 2015


Hello,

I have made this match method :

match_key( _Key, [] , List) ->
   List ;

match_key( Key, [Head | Tail], List ) ->
   case element(1, Head) of
     Key -> match_key(Key, Tail, [element(2,Head) | List] );
     _ -> match_key(Key, Tail,  List )
    end.

match( Key, [] ) ->
   {error, "Instance"};

match(Key, List) ->
   delete_key (Key, List, []).

But when I have this database.

Db5 :  [{name2,tamara},{name,chantal},{name,roelof}]

and I do this :

  Db11 = db:match(name,Db5).

I see this outcome :

[{name2,tamara}]

and when I do this :

  Db10 = db:match(name2,Db5).

I see this outcome:

[{name,roelof},{name,chantal}]

So it schould be the other way around.

Can someone help me figure out what went wrong ?

Roelof




More information about the erlang-questions mailing list