Hello!
I have a problem (see subject).
Depending on that the Map contains elements, the method below shall search for a key in a Map, remove the tuple corresponding to the key if found, and then insert a new tuple with its key and its values.
The map can for example look like this ("berlin" is the key in this case): [{berlin,[london,paris]}]
And the parameters to update can be: (berlin, [stockholm, oslo], [{berlin,[london,paris]}] ).
Here is my code:
update (Node, Links, Map) ->
if
%If empty list, than we shall add the node.
length (Map) /= 0 ->
%Search for an element in a list of Tuples.
case lists:keysearch (Node, length (Map), Map ) of
%We found the key gives the following pattern.
%Let's delete it and insert the new "Links"-list.
{value_corresponding_to_key, city_to_remove} ->
lists:delete (city_to_remove, Map);
false -> io:fwrite ("Test---Didnt find the key..") %We shall not remove anything.
end;
true -> io:fwrite ("") %If the other statement in the if-clause wasn't true, then do this.
end, %end if
lists:append (Map, [{Node, Links}]).
Here are my function call and my error-message in Erlide:
(erlide@AndersBarbara)5> map:update(berlin, [london, paris], [{berlin,[london,paris]}] ).
** exception error: no case clause matching {value,{berlin,[london,paris]}}
in function map:update/3
(erlide@AndersBarbara)6>
Thanks for your help!
Anders Branderud
My blog