Looking through the Elixir source I see that multiplication is defined like this:
@spec (number * number) :: number
def left * right do
:erlang.*(left, right)
end
I wanted to make a ** function to do power as an exercise. However, when I try, I get an exception and I can't figure out how to do it correctly.
@spec (number ** number) :: number
def left ** right do
:math.pow(left, right)
end
Always throws an error like:
** (SyntaxError) iex:7: syntax error before: '*'
I tried making it a macro, using unquote, using :"**" instead of **. Not sure why this doesn't work...
Any ideas?