Using guards like this works fine:
iex(1)> defmodule M do
...(1)> def update_position({pos, max_pos}) when pos < max_pos, do: pos + 1
...(1)> end
{:module, M, …
iex(2)> M.update_position({3,4})
4
iex(3)> M.update_position({3,3})
** (FunctionClauseError) no function clause matching in M.update_position/1
The following arguments were given to M.update_position/1:
# 1
{3, 3}
iex:2: M.update_position/1
But when extracting it into a defguard, the compiler gives a syntax error:
iex(1)> defmodule M2 do
...(1)> defguard is_valid_position({pos, max_pos}) when pos < max_pos
...(1)> end
** (ArgumentError) invalid syntax in defguard is_valid_position({pos, max_pos})
(elixir) lib/kernel.ex:4623: anonymous fn/2 in Kernel.validate_variable_only_args!/2
(elixir) lib/enum.ex:737: Enum."-each/2-lists^foreach/1-0-"/2
(elixir) lib/enum.ex:737: Enum.each/2
(elixir) lib/kernel.ex:4592: Kernel.define_guard/3
(elixir) expanding macro: Kernel.defguard/1
iex:2: M2 (module)
Anyone has a clue of the problem here?






















