Simple question

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Simple question

Nico Weling
Hi Erlang freaks,

I need OR within an case clause. Something like:


        case Name of
                peter OR klaus OR carsten ->
                        io:format("Is a man~n",[]);
                anna OR birgit OR petra ->
                        io:format("Is a woman~n", []);
                Other ->
                        io:format("Is a Zombie~n", [])
        end.

Is this possible, and if, how is the syntax.

Thanx a lot,

Nico.


Reply | Threaded
Open this post in threaded view
|

Simple question

Richard Carlsson-4

On Tue, 28 Aug 2001, Nico Weling wrote:

> Hi Erlang freaks,

Hi!

> I need OR within an case clause. ...
> Is this possible, and if, how is the syntax.

Try this:

  case Name of
            X when X == peter; X == klaus; X == carsten ->
  io:format("Is a man~n",[]);
     X when X == anna; X == birgit; X == petra ->
  io:format("Is a woman~n", []);
     _ ->
  io:format("Is a Zombie~n", [])
  end.

In other words, in a guard, you can have a ';'-separated sequence of
alternative conditions (a disjunction), where each condition is a
','-separated sequence of boolean tests (a conjunction).

(You could also use 'if' instead of 'case' for the above.)

  /Richard


Richard Carlsson (richardc)   (This space intentionally left blank.)
E-mail: Richard.Carlsson WWW: http://www.csd.uu.se/~richardc/



Reply | Threaded
Open this post in threaded view
|

Simple question

UAB/L/K Ingela Anderton konsult OTP

If you want to read about this in the documentation look under
Erlang Extensions Since 4.4 (I know it is not self-evident that there
is the place to look ;-)).

Richard Carlsson wrote:

>
> On Tue, 28 Aug 2001, Nico Weling wrote:
>
> > Hi Erlang freaks,
>
> Hi!
>
> > I need OR within an case clause. ...
> > Is this possible, and if, how is the syntax.
>
> Try this:
>
>   case Name of
>    X when X == peter; X == klaus; X == carsten ->
>   io:format("Is a man~n",[]);
>      X when X == anna; X == birgit; X == petra ->
>   io:format("Is a woman~n", []);
>      _ ->
>   io:format("Is a Zombie~n", [])
>   end.
>
> In other words, in a guard, you can have a ';'-separated sequence of
> alternative conditions (a disjunction), where each condition is a
> ','-separated sequence of boolean tests (a conjunction).
>
> (You could also use 'if' instead of 'case' for the above.)
>
>   /Richard
>
>
> Richard Carlsson (richardc)   (This space intentionally left blank.)
> E-mail: Richard.Carlsson WWW: http://www.csd.uu.se/~richardc/
--
/m.v.h Ingela

//The highway of life is always under construction. //

         |\      _,,,--,,_  ,)
                /,`.-'`'   -,  ;-;;'
               |,4-  ) )-,_ ) /\
              '---''(_/--' (_/-'

Ericsson Utvecklings AB

Cellular/Mobile: +46 70 636 78 68






Reply | Threaded
Open this post in threaded view
|

Simple question

snickl
In reply to this post by Nico Weling
On Tue, 28 Aug 2001, Nico Weling wrote:

> Hi Erlang freaks,
>
> I need OR within an case clause. Something like:
In function guards this is done with the semicolon (;) instead of ",",
but im not sure about the other places.

CU, SN
------
The UNIX equivalent of the "Blue Screen of Death" would be called
"kernel panic". It obviously exists, since I have heard and read about it,
but I've never been witness to it in my professional career.
        John Kirch,
        Networking Consultant and Microsoft Certified Professional (Windows NT)



Reply | Threaded
Open this post in threaded view
|

Simple question

Nico Weling
In reply to this post by Richard Carlsson-4
Thank you it's working!

Regards,

Nico.

Richard Carlsson wrote:

>
> On Tue, 28 Aug 2001, Nico Weling wrote:
>
> > Hi Erlang freaks,
>
> Hi!
>
> > I need OR within an case clause. ...
> > Is this possible, and if, how is the syntax.
>
> Try this:
>
>         case Name of
>             X when X == peter; X == klaus; X == carsten ->
>                         io:format("Is a man~n",[]);
>             X when X == anna; X == birgit; X == petra ->
>                         io:format("Is a woman~n", []);
>             _ ->
>                         io:format("Is a Zombie~n", [])
>         end.
>
> In other words, in a guard, you can have a ';'-separated sequence of
> alternative conditions (a disjunction), where each condition is a
> ','-separated sequence of boolean tests (a conjunction).
>
> (You could also use 'if' instead of 'case' for the above.)
>
>   /Richard
>
> Richard Carlsson (richardc)   (This space intentionally left blank.)
> E-mail: Richard.Carlsson      WWW: http://www.csd.uu.se/~richardc/

--
Nico Weling
Software Designer
Ericsson Eurolab Deutschland GmbH
Verification Tool Design

Tel: +49 2407 575 5217
Fax: +49 2407 575 651
Dect:+49 2407 575 89339
mailto:Nico.Weling