Consider this problem:
float (42) |> IO.inspect
What would you expect IO.inspect to print, 42 or 42.0?
If we consider the above translates to "float(42) |> IO.inspect", it should print 42.0.
However, if we consider it as "float((42) |> IO.inspect)", it should print 42.
In both cases, the result is 42.0 though.
In other words, the behaviour you see is a consequence of optional parenthesis and Elixir chooses the above to translate to "float((42) |> IO.inspect)".
This means that, when there is a space in between the function name and the parenthesis, Elixir considers the parenthesis apply to the first argument and not the function call. So:
float (42)
actually maps to:
float((42))
This means that:
if (this, do: that)
Translates to:
if((this, do: that))
And the following:
(this, do: that)
doesn't make sense on its own (you can't separate a regular parenthesis by comma). That's why you get an error message.
This is consistent with other optional parenthesis usage in Elixir. Try those:
float -4 + 5
float-4+5
A space after the function name always mean the start of the first argument. So the first example returns 1.0 and the second one fails, because it considers you are calling float(), with no arguments.
In any case, I believe the error message could be better.
José Valim
Skype: jv.ptec
Founder and Lead Developer