Login function and pattern matching

chandru chandrashekhar.mullaparthi@REDACTED
Fri Aug 26 05:29:29 CEST 2005


Hi,

On 25/08/05, Joel Reymont <joelr1@REDACTED> wrote:
> Folks,
> 
> I'm building a login function for my poker server and this function
> can return different results based on the values of different fields
> in the player record.
> 
> I would love to do the login function using pattern matching but
> since custom guards are not allowed am I stuck with a dispatch
> function that verifies my conditions and calls other functions as
> needed?
> 

You can do this thus.

-record(login, {name, password, other_field1, other_field2}).

auth_user(#login{name=Name, password=Password} = LoginRec) ->
    case my_password_db:auth_user(Name, Password) of
           ok ->
                extra_auth(LoginRec);
           Err ->
                 Err
    end.

extra_auth(#login{other_field1 = "val1"}) ->
     do_stuff;
extra_auth(#login{other_field2 = "val2"}) ->
     do_someother_stuff.

Or have I not understood your problem?

cheers
Chandru



More information about the erlang-questions mailing list