<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">The first example would probably be better as</div><div class="gmail_default" style="font-family:monospace,monospace"> if X =:= 4 -> first case</div><div class="gmail_default" style="font-family:monospace,monospace"> ; X >= 2, X =< 6 -> third case</div><div class="gmail_default" style="font-family:monospace,monospace"> ; true -> second case</div><div class="gmail_default" style="font-family:monospace,monospace"> end</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">The second example makes me unhappy. We are so far in the misty clouds of</div><div class="gmail_default" style="font-family:monospace,monospace">abstraction here that we can't see the ground with a telescope. And the</div><div class="gmail_default" style="font-family:monospace,monospace">thing that makes me unhappy is the "_" case. This is a maintenance bug</div><div class="gmail_default" style="font-family:monospace,monospace">waiting to happen, and it does not matter what your programming language is.</div><div class="gmail_default" style="font-family:monospace,monospace">This is the ML lesson. A concrete example would be a big help.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 11 Feb 2019 at 08:43, Hugo Mills <<a href="mailto:hugo@carfax.org.uk">hugo@carfax.org.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sun, Feb 10, 2019 at 02:33:36PM -0500, Donald Steven wrote:<br>
> Newbie question regarding best practices (including a string of nested ifs):<br>
> <br>
> How do you code the following:<br>
<br>
Guards:<br>
<br>
> case X of<br>
> 4 -> something;<br>
> <2 or >6 -> something else;<br>
> _ -> something else again<br>
> end,<br>
<br>
case X of<br>
4 -><br>
something;<br>
Y when Y < 2; Y > 6 -><br>
something else;<br>
_ -><br>
something else again<br>
end,<br>
<br>
Note that >=2 and =<6 would be written with "when Y >= 2, Y =< 6" --<br>
use comma for "and", semicolon for "or", with "or" being at the higher<br>
level:<br>
<br>
Y when Y >= 2, Y =< 6; Y >= 8, Y =< 10 -><br>
Y is either between 2 and 6 or between 8 and 10 inclusive;<br>
<br>
> and<br>
> <br>
> case X of<br>
> atom1 or atom2 or atom3 -> something;<br>
> atom4 -> something else;<br>
> _ -> -> something else again<br>
> end,<br>
<br>
case X of<br>
Y when Y =:= atom1; Y =:= atom2; Y =:= atom3 -><br>
something;<br>
atom4 -><br>
something else;<br>
_ -><br>
something else again<br>
end,<br>
<br>
Hugo.<br>
<br>
-- <br>
Hugo Mills | I have a step-ladder. My real ladder left when I was<br>
hugo@... <a href="http://carfax.org.uk" rel="noreferrer" target="_blank">carfax.org.uk</a> | a child.<br>
<a href="http://carfax.org.uk/" rel="noreferrer" target="_blank">http://carfax.org.uk/</a> |<br>
PGP: E2AB1DE4 |<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>