Hey,
I am currently reading Programming Elixir and I am doing one of the exercises where you should write a solution to the “I’m thinking of a number between 1 and 1000”
I have made it work, but I wanted to add a simple guard clause: I want to check if the passed number is actually in the passed range. As far as I have read only handful of functions and operators are allowed in guard clauses, but the ‘in’ is one of them.
So 1st I tried this:
def guess(actual, range) when (actual not in range), do: IO.puts "actual #{actual} is not in #{range}"
But I got: (ArgumentError) invalid args for operator “in”, it expects a compile-time proper list or compile-time range on the right side.
2nd I tried to make a list from the range:
def guess(actual, range) when (actual not in (Enum.to_list range), do: IO.puts "actual #{actual} is not in #{range}
And again I got the same error, this time saying that I the right side is the function itself instead the evaluation of it, which should be proper list ?!?
But this works(when the range is defined in the guard clause) :
def test(x) when(x not in 1..100) …






















