[erlang-questions] Guards syntax for multiple values

Richard O'Keefe raoknz@REDACTED
Mon Mar 25 07:32:56 CET 2019


lists:member(X, [X1,X2,X3,X4]) answers true or false.
There is no fundamental reason that the compiler could not
expand that in-line to (X =:= X1 orselse ... orelse X =:= X4)
when the shape of the list is known.  So we *definitely* need
no new syntax.

However, I must repeat that if this happens often enough in your code
to be "boring" you need to give serious thought to changing your data
structure.  Things that share a processing path should be given a
common structure.

We really need an actual concrete example of real code to discuss.


On Mon, 25 Mar 2019 at 18:12, Florent Gallaire <fgallaire@REDACTED> wrote:

> Frank thanks for your answer.
>
> > You’re probably new to Erlang.
>
> Yes, but...
>
> > You can achieve the same with parse_transform:
> > https://github.com/mad-cocktail/gin/blob/master/README.rst
>
> ...I can say parse_transform is not the solution Erlang needs.
>
> > There’s no point to add new syntax to the language.
>
> Yes we need it, an easy to use built-in "in (tuple or list I'm not
> sure of the right semantic)" syntactic sugar for guards.
>
> Hope some other advices.
>
> Florent
>
> > /Frank
> >
> >> Hello everybody,
> >>
> >> I'm not very experimented in Erlang but I read carefully books and
> >> official documention.
> >>
> >> It seems to me that the guards syntax is not as good as it should be,
> >> i.e. too much verbose for multiple values.
> >>
> >> do(val1) -> val1;
> >> do(val2) -> val2;
> >> do(val3) -> val3;
> >> do(val4) -> val4;
> >> do(val5) -> val5.
> >>
> >> do(Val) when Val =:= val1; Val =:= val2; Val =:= val3; Val =:= val4;
> >> Val =:= val5 -> Val.
> >>
> >> It's boring and error prone to write.
> >>
> >> Has a "in tuple" syntax already be considered ? Something like :
> >>
> >> do(Val) when Val in {val1, val2, val3, val4, val5} -> Val.
> >>
> >> Cheers
> >>
> >> Florent
> >>
> >> --
> >> FLOSS Engineer & Lawyer
> >> _______________________________________________
> >> erlang-questions mailing list
> >> erlang-questions@REDACTED
> >> http://erlang.org/mailman/listinfo/erlang-questions
>
>
>
> --
> FLOSS Engineer & Lawyer
> _______________________________________________
> 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/20190325/412a8bc1/attachment.htm>


More information about the erlang-questions mailing list