[erlang-questions] Erlang elseif
John Hughes
john.hughes@REDACTED
Thu Nov 20 10:09:29 CET 2008
Here's another list-comprehension way
elseif(A) ->
[io:format("Member of capital\n") || lists:member(A,?CAPS)],
[io:format("Member of small\n") || lists:member(A,?SMALL)],
[io:format("Member of nums\n") || lists:member(A,?NUMS)],
ok.
OK, it's not else-if, rather a sequence of if-thens, but it does the same
job and it's short and sweet.
John Hughes
> From: kdronnqvist@REDACTED
> Subject: [erlang-questions] Erlang elseif
> To: erlang-questions@REDACTED
> Message-ID:
> <65691fa00811200041yfc7a219y97a11126e0cee535@REDACTED>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi everyone I just joined the list and tried to search for information
> about
> this but I could not find anything that answered my question. The thing is
> that I want a general way to branch the execution of my code based on the
> result on an expression. Very similar to how if works but I want to be
> able
> to test expressions and not only guards. If you're thinking "then you have
> case" now look below at function elseif2() and you'll see my point.
>
> I wrote a couple of examples how to solve this but none of them really
> feels
> right, the logic in what I'm trying to do is really REALLY not that
> complicated. The functions takes an argument and prints something based on
> what list the argument is a member of (if any). Like this:
>
> 42> e:elseif4($Q).
> Member of capital
>
>
> I would appreciate any input on this, even if it means you're bashing all
> my
> examples below :-)
>
> BR,
> Daniel R?nnqvist
More information about the erlang-questions
mailing list