doubt regarding nested if blocks

Bengt Kleberg bengt.kleberg@REDACTED
Fri Aug 12 08:41:04 CEST 2005


On 2005-08-12 08:04, MEENA SELVAM wrote:
> In the following code sample, if the commented
> line(line 7) is uncommented, compilation is
> successful, but with the comment it crashes during
> compilation, (which i have included at the end)
> 
> how can i get around the crash without introducing
> dummy statement? why does it crash at all?
> 
>  case Cookie of
>              not_found ->
>                 "no_vlan";
>              _ ->
>                 {_,_,_,Dcookie,Pcookie} = Cookie,    
>                 if Dcookie == undefined ->
>                       %  dummy=1,
>                         if Pcookie == undefined ->
>                             [CE] = [],
>                             skip = 1;
>                         true->
>                              [CE] = lookup_x(Pcookie ,
> false)
>                         end;
>                 true->
>                     [CE] = lookup_x(Dcookie , false)
>                 end,
>                 if skip /= 1 ->
>                         case ?CACHE_SNAS_INFO(CE) of
>                         Dev = #device{} ->
>  
>                                 Dev#device.vlan;
>                         undefined ->
>                                 "no vlan"
>                         end;
>                 true -> "no_vlan"
>                 end
>         end.

i can not reproduce your crash.


i added a module, function head and a macro definition. i then compiled 
the function. it compiled (with lots of warnings and errors). by adding 
dummy functions and a record i got a clean compile.
erlc does not have a versin(?), but erl says:
Erlang (THREADS,HIPE) (BEAM) emulator version 5.4.7


btw: are you matching the atom 'skip' with the integer 1 to cause a run 
time crash?
 >                             skip = 1;
would it not be clearer to call erlang:throw(), or similarfunction, instead?

and please consider rewriteing
 >                 if skip /= 1 ->
would it not be clearer as
	if false ->

also consider rewriteing
 >                         case ?CACHE_SNAS_INFO(CE) of
 >                         Dev = #device{} ->
 >                                 Dev#device.vlan;
as
	case ?CACHE_SNAS_INFO(CE) of
	#device{vlan=Vlan} ->
		Vlan;


bengt



More information about the erlang-questions mailing list