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

Ulf Wiger etxuwig@REDACTED
Thu Feb 6 12:27:09 CET 2003

On Thu, 6 Feb 2003, Richard Carlsson wrote:

>On Thu, 6 Feb 2003, Bengt Kleberg wrote:
>> i would like to do the following:
>> dpid_to_if(Dp, Domain) ->
>>     case Dp of
>> 	Domain#prswDomain.working_dp ->
>> 	    Domain#prswDomain.working_if;
>> 	Domain#prswDomain.protection_dp ->
>> 	    Domain#prswDomain.protection_if
>>     end.
>> i know the workaround, but why is this an illegal pattern?
>What your attempted pattern wants to test (i guess) is that
>"in case Dp is *the 'working_dp' element of* the
>'prswDomain'-record Domain ...", but that would be
>equivalent to:
>	case Dp of
>	    element(5, Domain) -> ...
>To be more formalistic about why that can't be made into a
>pattern: patterns describe the static skeleton of the data
>(counting pre-bound variables as static), and a pattern
>like this one would not be static.

Why wouldn't it be, if it's an intuitive way to express the
pattern? All suggested alternatives are less intuitive,

Isn't this really an artifact of the syntactic expansion of
record expressions?

One could imagine that the compiler (knowing the size of the
prswDomain record) generate code like this:

dpid_to_if(Dp, Domain) ->
   __working_dp = Domain#prswDomain.working_dp,
   __protection_if = Domain#prswDomain.protection_if,
   case Dp of
     __working_dp ->
     __protection_if ->

Why whould that not be valid?

Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson Telecom AB, ATM Multiservice Networks

More information about the erlang-questions mailing list