[erlang-questions] Trouble with Erlang's lenient comparisons

Kostis Sagonas kostis@REDACTED
Wed Apr 13 12:36:38 CEST 2011


Gordon Guthrie wrote:
>...
> 
> Also check for bad input to functions by using guards like:
> 
> fun(A, B, C) when is_list(A), is_integer(B), is_record(C, recC) ->

The following is a bit pedantic, but please do not offer use of the 
is_record guard (esp. the one with arity two instead of three) as advice 
to newcomers.  I suggest that you try to forget about this guard's 
existence; the only place where this guard is possibly needed is in 
or/orelse contexts.

The above code is written better using pattern matching, as in:

   fun(A, B, #recC{} = C) when is_list(A), is_integer(B) ->

Kostis



More information about the erlang-questions mailing list