[erlang-questions] Function clause question
Ulf Wiger
ulf@REDACTED
Fri Dec 26 08:53:46 CET 2008
It's basically a matter of taste, but in your specific example,
there is also a semantic difference:
[_H | _T] matches only if the list is non-empty, whereas
(Arg, Bin) when is_list(Arg)
also matches empty lists.
<<Arg/binary>> does match the empty binary, though.
BR,
Ulf W
2008/12/26 Camille Troillard <tuscland@REDACTED>:
> Dear list,
> I have a simple best practices question:
> Is it better to write:
>
> skip ([_H | _T] = Arg, Bin) ->
> skip_count (length (Arg) + 1, Bin);
> skip (<<Arg/binary>>, Bin) ->
> skip_count (size (Arg), Bin).
> or
> skip (Arg, Bin) when is_list (Arg) ->
> skip_count (length (Arg) + 1, Bin);
> skip (Arg, Bin) when is_binary (Arg) ->
> skip_count (size (Arg), Bin).
> I would be in favor or the second case, but I wonder if the use of guards in
> this case is a very good idea.
>
> Best,
> Cam
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list