multiple patterns per clause?
Bengt Kleberg
bengt.kleberg@REDACTED
Mon Aug 28 17:02:02 CEST 2006
On 2006-08-28 16:47, Yariv Sadan wrote:
> Hi,
>
> Is it possible to have a single clause match multiple patterns in Erlang?
no. use functions for that.
> Specifically, I want to test if a list has a number of different
> prefixes, all of which would lead to the same expression.
which would be:
case is_prefix_i_want( L ) of
true -> ok;
false -> error
end
is_prefix_i_want([$f|_] ) -> true;
is_prefix_i_want([$x|_] ) -> true;
is_prefix_i_want([$a, $b, $c|_] ) -> true;
is_prefix_i_want( _ ) -> false.
this was an attempt to match your (pseudo)code.
in this particular case it would have been better to use:
prefix_i_want( L )
prefix_i_want([$f|_] ) -> ok;
prefix_i_want([$x|_] ) -> ok;
prefix_i_want([$a, $b, $c|_] ) -> ok;
prefix_i_want(_ ) -> error.
but i guess that is not really what you want :-)
bengt
--
EPO guidelines 1978: "If the contribution to the known art resides
solely in a computer program then the subject matter is not
patentable in whatever manner it may be presented in the claims."
More information about the erlang-questions
mailing list