Erlang code critique

Posted by dagda1 on Stack Overflow See other posts from Stack Overflow or by dagda1
Published on 2010-04-17T20:25:37Z Indexed on 2010/04/17 22:43 UTC
Read the original article Hit count: 342

Filed under:

Hi,

I am trying to get my head round some basic erlang functionality and I could do with some comments on the following.

I have the following erlang code that takes a list of tuples and returns a list minus an element if a key is found:

delete(Key, Database) ->
    remove(Database, Key, []).

remove([], Key, Acc) ->
    Acc;
remove([H|T], Key, Acc) ->
    if
        element(1, H) /= Key ->             
            [H| remove(T, Key, Acc)];
        true  -> 
            remove(T, Key, Acc)
    end.

Is this a good way of doing this?

The if statement seems incorrect.

Also is my use of the accumulator Acc making this tail recursive?

Cheers

Paul

© Stack Overflow or respective owner

Related posts about erlang