[erlang-questions] Guards syntax for multiple values

Florent Gallaire fgallaire@REDACTED
Wed Mar 27 03:39:10 CET 2019


-define(DIGITS, "0123456789").
-define(LOWERCASE, "abcdefghijklmnopqrstuvwxyz").
-define(UPPERCASE, "ABCDEFGHIJKLMNOPQRSTUVWXYZ").
-define(FRACTIONS, "½⅓⅔¼¾⅕⅖⅗⅘⅙⅚⅐⅛⅜⅝⅞⅑⅒")

A standard .hlr include file could be a nice plus.

is_fraction(X) when is_member(?FRACTIONS, X) -> true.

char_unreserved(Char)
    when is_member(?DIGITS, Char);
         is_member(?UPPERCASE, Char);
         is_member(?LOWERCASE, Char);
         is_member("~_-.", Char) ->
  true;

Kill the need of integer tricks (yes it's fun, but error-prone and not
beginners friendly) will be a nice side-effect.

Cheers

Florent

Le mer. 27 mars 2019 à 02:55, Florent Gallaire <fgallaire@REDACTED> a écrit :
>
> Tanks a lot José for your great examples, even if obvious for me some
> people seem to really need them.
>
> > char_unreserved(Char)
> >     when Char >= ?0, Char =< ?9;
> >          Char >= ?A, Char =< ?Z;
> >          Char >= ?a, Char =< ?z;
> >          is_member("~_-.", Char) ->
> >   true;
> >
>
> char_unreserved(Char)
>     when is_member("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~_-.")
> ->
> true;
>
> Cheers
>
> Florent
>
> > char_unreserved(Char) when Char >= 0, Char <= 16x10FFFF ->
> >
> >   false.
> >
> >
> > And similar for reserved characters:
> >
> > char_reserved(Char)
> >     when is_member(":/?#[]@!$&\'()*+,;=", Char) ->
> >
> >   true;
> >
> > char_reserved(Char) when Char >= 0, Char <= 16x10FFFF ->
> >
> >   false.
> >
> >
> > There are likely other examples but this should be enough to push the discussion forward.
> >
> > José Valim
> > www.plataformatec.com.br
> > Skype: jv.ptec
> > Founder and Director of R&D
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
>
>
>
> --
> FLOSS Engineer & Lawyer



-- 
FLOSS Engineer & Lawyer



More information about the erlang-questions mailing list