[erlang-questions] Basic Erlang case question

Richard Carlsson richardc@REDACTED
Thu Jul 10 13:59:46 CEST 2008


Serge Aleynikov wrote:
> Here's a tricky part - if you define some other use of MD5_Password 
> between the first case statement and the second, the warning in your 
> original code would go away.  It looks like when the variable exported 
> from the case clause is used elsewhere as a rhs in pattern match then 
> its safe to use it on lhs as well.

Yes, the warning is limited to this particular case, since it is the
one which typically could be a programming mistake:

   f(...) ->
       case ... of
           {..., X, ...} -> ...;
           ...
           {..., X, ...} -> ...
       end,
       ...
       ...
       case ... of
           {..., X, ...} -> ...;
           ...
           {..., X, ...} -> ...
       end.

where X is intended to be a "local" temp variable, but due to some
copy-and-pasting or other reason, X is then used again in a pattern
further down (might be easy to miss if the function is large). The
variable export is a language feature (like it or not) and it would
be annoying to warn for other, probably intentional uses, so this
is a compromise.

     /Richard



More information about the erlang-questions mailing list