Elixir does not recognize a varibale and extends it as a function. Why does this happen?

As @zwippie suggests, you need to put the string_to_num/4 with the [] first param first, since if the first param is [], the first clause will match, with [] being assigned to string_grahemes. You should then be getting a compiler warning to that effect.

You should also be getting a compiler warning:

warning: defp string_to_num/4 has multiple clauses and also declares default values. In such cases, the default values should be defined in a header. Instead of:

    def foo(:first_clause, b \\ :default) do ... end
    def foo(:second_clause, b) do ... end

one should write:

    def foo(a, b \\ :default)
    def foo(:first_clause, b) do ... end
    def foo(:second_clause, b) do ... end