chapter 12

38 views
Skip to first unread message

douglasv

unread,
Jul 22, 2011, 11:56:28 AM7/22/11
to Erlang Programming

usr calls usr_db:add_usr/3 while usr_db is add_usr/2

add_usr arity 2 and arity 3 mismatch
what am I missing?

--(module usr)--
handle_call({add_usr, PhoneNo, CustId, Plan}, _From, LoopData) ->
Reply = usr_db:add_usr(#usr{msisdn=PhoneNo,
id=CustId,
plan=Plan}),
{reply, Reply, LoopData};

--(module usr_db)--
add_usr(#usr{msisdn=PhoneNo, id=CustId} = Usr) ->
ets:insert(usrIndex, {CustId, PhoneNo}),
update_usr(Usr).

Ale

unread,
Jul 22, 2011, 12:06:34 PM7/22/11
to erlang-prog...@googlegroups.com
> handle_call({add_usr, PhoneNo, CustId, Plan}, _From, LoopData) ->
>  Reply = usr_db:add_usr(#usr{msisdn=PhoneNo,
>                              id=CustId,
>                              plan=Plan}),

> --(module usr_db)--


> add_usr(#usr{msisdn=PhoneNo, id=CustId} = Usr) ->

This looks like its add_user/1 not 2 or 3, add_user takes a record as
an argument.

In the function definition you are pattern-matching the record, and
defining Phone as the msisdn attribute of the record and CustId as the
id attribute of the record.

While on the function call you are creating a new record with msisdn
as Phone, id as CustId and plan as Plan.

Again only one argument, a record.

Cheers, hope it helps


--
Ale.

douglas

unread,
Jul 22, 2011, 12:35:01 PM7/22/11
to erlang-prog...@googlegroups.com
than you sir

Cheers, hope it helps


--
Ale.

--
Erlang Programming Website:
http://www.erlangprogramming.org/

Reply all
Reply to author
Forward
0 new messages