[erlang-questions] Compound guard expression in case
Richard O'Keefe
raoknz@REDACTED
Mon Feb 11 01:17:29 CET 2019
The first example would probably be better as
if X =:= 4 -> first case
; X >= 2, X =< 6 -> third case
; true -> second case
end
The second example makes me unhappy. We are so far in the misty clouds of
abstraction here that we can't see the ground with a telescope. And the
thing that makes me unhappy is the "_" case. This is a maintenance bug
waiting to happen, and it does not matter what your programming language is.
This is the ML lesson. A concrete example would be a big help.
On Mon, 11 Feb 2019 at 08:43, Hugo Mills <hugo@REDACTED> wrote:
> On Sun, Feb 10, 2019 at 02:33:36PM -0500, Donald Steven wrote:
> > Newbie question regarding best practices (including a string of nested
> ifs):
> >
> > How do you code the following:
>
> Guards:
>
> > case X of
> > 4 -> something;
> > <2 or >6 -> something else;
> > _ -> something else again
> > end,
>
> case X of
> 4 ->
> something;
> Y when Y < 2; Y > 6 ->
> something else;
> _ ->
> something else again
> end,
>
> Note that >=2 and =<6 would be written with "when Y >= 2, Y =< 6" --
> use comma for "and", semicolon for "or", with "or" being at the higher
> level:
>
> Y when Y >= 2, Y =< 6; Y >= 8, Y =< 10 ->
> Y is either between 2 and 6 or between 8 and 10 inclusive;
>
> > and
> >
> > case X of
> > atom1 or atom2 or atom3 -> something;
> > atom4 -> something else;
> > _ -> -> something else again
> > end,
>
> case X of
> Y when Y =:= atom1; Y =:= atom2; Y =:= atom3 ->
> something;
> atom4 ->
> something else;
> _ ->
> something else again
> end,
>
> Hugo.
>
> --
> Hugo Mills | I have a step-ladder. My real ladder left when I
> was
> hugo@REDACTED carfax.org.uk | a child.
> http://carfax.org.uk/ |
> PGP: E2AB1DE4 |
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190211/c22de282/attachment.htm>
More information about the erlang-questions
mailing list