I'm currently trying my hand at Elixir. I have very little experience with either Ruby or functional programming so I'm not too familiar with the syntax. I was reading Learn Elixir in Y minutes and I was a bit confused by one of the examples. At first, the guide showed the case control-flow structure, which I understood just fine.
case {:one, :two} do
{:four, :five} ->
"This won't match"
{:one, x} ->
"This will match and bind `x` to `:two` in this clause"
_ ->
"This will match any value"
end
However, one of the last examples that was shown was one about recieving messages from other processes. It had a very similar syntax and structure to the case example but it did not use the case keyword. It looks to me like some sort of anonymous case syntax for use with functions which can take differing arguments.
defmodule Geometry do
def area_loop do
receive do
{:rectangle, w, h} ->
IO.puts("Area = #{w * h}")
area_loop()
{:circle, r} ->
IO.puts("Area = #{3.14 * r * r}")
area_loop()
end
end
end
What is the difference between these two syntaxes?