multiple patterns per clause?

Yariv Sadan yarivvv@REDACTED
Tue Aug 29 22:25:04 CEST 2006


Good point. Thanks!

On 8/29/06, Raimo Niskanen <raimo+erlang-questions@REDACTED> wrote:
> You could group the clauses a bit:
>
>         case L of
>             [L1|_] when L1 =:= $f; L1 =:= $x ->
>                 ok;
>             "abc"++_ ->
>                 ok
>             _ ->
>                 error
>         end
>
> On Mon, Aug 28, 2006 at 10:47:38AM -0400, Yariv Sadan wrote:
> > Hi,
> >
> > Is it possible to have a single clause match multiple patterns in Erlang?
> >
> > Specifically, I want to test if a list has a number of different
> > prefixes, all of which would lead to the same expression.
> >
> > This is what I want to write (pseudo code):
> >
> > L = "foo",
> > case L of
> >  [$f|_];
> >  [$x|_] ;
> >  [$a, $b, $c | _] ->
> >    ok;
> >  _ ->
> >    error
> > end
> >
> > I know the above is illegal, so what's the easiest way of doing
> > something similar in Erlang?
> >
> > Thanks in advance,
> > Yariv
>
> --
>
> / Raimo Niskanen, Erlang/OTP, Ericsson AB
>



More information about the erlang-questions mailing list