[erlang-questions] Guards syntax for multiple values

Bryan Hunt bryan.hunt@REDACTED
Mon Mar 25 12:50:11 CET 2019


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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190325/92ba5ad2/attachment.htm>


More information about the erlang-questions mailing list