A reasonable way of doing it would be:<br><br>case is_vowel(Char) of<br>    true -> ... ;<br>    false -> ...<br>end<br><br>with<br><br>is_vowel($a) -> true;<br>...<br>is_vowel(_) -> false.<br><br>It is clear what you are doing and it is easy to extend is_vowel/1 with new rule when more vowels are added. It also has the benefit of abstracting out the tests and making sure that all vowel testing in the code will always be correct.<br>
<br>Robert<br><br><div class="gmail_quote">2008/11/5 Colm Dougan <span dir="ltr"><<a href="mailto:colm.dougan@gmail.com">colm.dougan@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
I often find myself writing code like this :<br>
<br>
(Note: I'm only using vowels as a contrived example here).<br>
<br>
   case Char of<br>
     Vowel when Vowel =:= $a;<br>
     Vowel =:= $e;<br>
     Vowel =:= $i;<br>
     Vowel =:= $o;<br>
     Vowel =:= $u -><br>
        io:format("Handling vowel~n");<br>
     _ -><br>
        io:format("Not a vowel~n")<br>
   end.<br>
<br>
Is there any better idiom for this?  It usually becomes long-winded.<br>
For example, it would seem ideal to be able to do this :<br>
<br>
   case Char of<br>
     $a; $e; $i; $o; $u -><br>
         io:format("Handling vowel~n");<br>
    _ -><br>
        io:format("Not a vowel~n")<br>
   end.<br>
<br>
Yeah I realise I could write function either with one massive guard<br>
statement or something like this :<br>
<br>
handle_char($a) -> handle_vowel($a);<br>
handle_char($e) -> handle_vowel($e);<br>
handle_char($i) -> handle_vowel($i);<br>
handle_char($o) -> handle_vowel($o);<br>
handle_char($u) -> handle_vowel($u);<br>
handle_char(Char) -> handle_non_vowel(Char).<br>
<br>
.. which is a nice approach but sometimes an inline case statement is<br>
all you want.<br>
<br>
Thanks,.<br>
Colm<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br>