clarification needed in this code snippet

MEENA SELVAM meena_selvam@REDACTED
Sat Jul 9 17:22:32 CEST 2005


Hi,

I have not understood how the following code
functions:

To me, it appears that in lines 8-9, pattern matching
occurs based on the output of pc_lookup function, and
the unbound variable Cookie gets bound to either
undefined or any other value. Different actions are
taken depending on Cookie value.

But the output of pc_lookup should be a port_cache
record for this to happen.

But according to definition of pc_lookup, the output
is a record of type sac_port_cache.

This is a working code, and I don't follow the
discrepancy in the record type of the output. Can
anyone clarify for me? 
 
1 %% xsp  = {xid(), sid(), int()}

2 -record(port_cache, {xsp, type, dcookie, pcookie}).
3 -define(PC_TAB, sac_port_cache).

...
...

4 init() ->
5    ets:new(?PC_TAB, [set, protected, named_table,
{keypos, #port_cache.xsp}]),

...

6 existing_dyn_sessionp(Switch, Port, Mac) ->
7    XSP = mk_xsp(Switch, Port),
8    case pc_lookup(XSP) of

9	#port_cache{ dcookie = Cookie } when Cookie /=
undefined ->
	    ....

10	#port_cache{ dcookie = Cookie } when Cookie ==
undefined ->
	    .....
11    end.
...
...
12 pc_lookup(XSP) ->
13    case ets:lookup(?PC_TAB, XSP) of
14	[Val] ->
15	    Val;
16	[] ->
17	    not_found
18    end.



		
____________________________________________________
Sell on Yahoo! Auctions – no fees. Bid on great items.  
http://auctions.yahoo.com/



More information about the erlang-questions mailing list