''illegal pattern'' when using records in case statement

Vladimir Sekissov <>
Thu Feb 6 02:22:05 CET 2003


From: Bengt Kleberg <>
Subject: ''illegal pattern'' when using records in case statement
Date: Thu, 6 Feb 2003 11:05:35 +0100 (MET)
Message-ID: <>

Good day,

eleberg> dpid_to_if(Dp, Domain) ->
eleberg>     case Dp of
eleberg> 	Domain#prswDomain.working_dp ->
eleberg> 	    Domain#prswDomain.working_if;
eleberg> 	Domain#prswDomain.protection_dp ->
eleberg> 	    Domain#prswDomain.protection_if
eleberg>     end.

The pattern couldn't be computable. The following code would be
correct:

-record(prswDomain,
	{domain, working_if, protection_if, working_dp,
	 protection_dp}).

dpid_to_if(Dp, Domain) ->
    case Dp of
	V when V == Domain#prswDomain.working_dp ->
	    Domain#prswDomain.working_if;
	V when V == Domain#prswDomain.protection_dp ->
	    Domain#prswDomain.protection_if
    end.

or better:

dpid_to_if(Dp, Domain=#prswDomain{working_dp=Dp, working_if=Ret}) ->
  Ret;
dpid_to_if(Dp, Domain=#prswDomain{protection_dp=Dp, protection_if=Ret}) ->
  Ret.

Best Regards,
Vladimir Sekissov

eleberg> -record(prswDomain,
eleberg> 	{domain, working_if, protection_if, working_dp,
eleberg> 	 protection_dp}).
eleberg> 
eleberg> dpid_to_if(Dp, Domain) ->
eleberg>     case Dp of
eleberg> 	Domain#prswDomain.working_dp ->
eleberg> 	    Domain#prswDomain.working_if;
eleberg> 	Domain#prswDomain.protection_dp ->
eleberg> 	    Domain#prswDomain.protection_if
eleberg>     end.



More information about the erlang-questions mailing list