Good practice

Vladimir Sekissov svg@REDACTED
Sun Jun 8 22:35:55 CEST 2003


Good day,

Some ways are:

1. Single value return:

Response =
 case checkvalid(Funcref, Correctlist) of
   false ->
     false;
   Other ->
     invoker(Other, Otherargs)
 end,
 Requester ! Response,  

2. Multiple values with pattern-matching and tuples/lists/records:

{R1, R2} =
 case checkvalid(Funcref, Correctlist) of
   false ->
     {false, true};
   Other ->
     invoker(Other, Otherargs)
 end,
 Requester1 ! R1,  
 Requester2 ! R2,

3. Simplified non-local return with catch/throw to avoid many nested clauses:

Response =
  case catch
    begin
     ...
     case checkvalid(Funcref, Correctlist) of
       false ->
        throw({ok, false});
       _ ->
        ok
     end,
     ...
     case invoker(Other, Otherargs) of
        true ->
          throw({ok, true});
         _ ->
           ok
     end,
     ...
    end of
     {ok, V} ->
       V;
     Error ->
       exit(Error)
  end,
 Requester ! Response,  

Best Regards,
Vladimir Sekissov

erlang> >From the file in question:
erlang> 
erlang>       case checkvalid(Funcref, Correctlist) of
erlang>         false ->
erlang>           Response = false;
erlang>         Other ->
erlang>           Response = invoker(Other, Otherargs)
erlang>       end,
erlang>       Requester ! Response,  
erlang> 
erlang> Obviously the warning warns me of a problem.  This I expect, and welcome.
erlang> However, that doesn't mean I want to see warnings; I want to do things
erlang> right.  I could just put the message in the case statement, I suppose, but
erlang> is there really a canonical way of doing the above without getting the
erlang> complaint?



More information about the erlang-questions mailing list