[erlang-questions] Guards syntax for multiple values

Florent Gallaire fgallaire@REDACTED
Mon Mar 25 18:03:22 CET 2019


Hello Bryan,

thanks for your answer.

Indeed it's very intersting to note that the only thing added to
Erlang guards when designing Elixir has been this "in list" (and "not
in") operator.

For people who don't know about Elixir, it's a BEAM based programming
language with a tremondous succes.

All (alive) programming languages  are evolving influenced by others,
Erlang evolve too, even for syntactic sugar, and it's GOOD.

For reasons of taste, I prefer Erlang over Elixir, and my "in list"
operator need comes obviously from my important Python experience.

As Loïc said "It's just nicer to read and write", it's just better for
beginnings, and so better for any programmers, and so better for
Erlang.

Cheers

Le lun. 25 mars 2019 à 12:50, Bryan Hunt
<bryan.hunt@REDACTED> a écrit :
>
> Pretty easy to do with Elixir - also runs on beam and is a bit more expressive e.g.
>
> iex(1)> "foo" in ["foo","bar"]
> true
> iex(4)> defmodule T do
> ...(4)> def f(x) when x in ["foo","bar"] do
> ...(4)> true
> ...(4)> end
> ...(4)> def f(x), do: false
> ...(4)> end
> warning: variable "x" is unused (if the variable is not meant to be used, prefix it with an underscore)
>   iex:8
>
> {:module, T,
>  <<70, 79, 82, 49, 0, 0, 4, 100, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 128,
>    0, 0, 0, 15, 8, 69, 108, 105, 120, 105, 114, 46, 84, 8, 95, 95, 105, 110,
>    102, 111, 95, 95, 7, 99, 111, 109, 112, ...>>, {:f, 1}}
> iex(5)> T.f
> f/1
> iex(5)> T.f("bar")
> true
> iex(6)> T.f("baz")
> false
>
>


-- 
FLOSS Engineer & Lawyer



More information about the erlang-questions mailing list