So I’m trying to full-fill the interface of an erlang library, however it seems I’ve hit a design fault in Elixir in regards to intercompatability…
In Erlang a function name can be any atom, so in other words anything, however in Elixir function names are arbitrarily constrained and it seems that an atom cannot be used. I’m needing to define a function name that contains $
in it, and I am needing to call a function name that contains a $
in it, however I’ve tried all of the following variants to no avail:
iex> defmodule Testering do def $blah$, do: 42 end
** (SyntaxError) iex:4: unexpected token: "$" (column 28, codepoint U+0024)
iex> defmodule Testering do def :$blah$, do: 42 end
** (SyntaxError) iex:4: unexpected token: ":" (column 28, codepoint U+003A)
iex> defmodule Testering do def :"$blah$", do: 42 end
warning: redefining module Testering (current version defined in memory)
iex:4
** (CompileError) iex:4: invalid syntax in def :"$blah$"
iex:4: (module)
iex> defmodule Testering do def :'$blah$', do: 42 end
warning: redefining module Testering (current version defined in memory)
iex:4
** (CompileError) iex:4: invalid syntax in def :"$blah$"
iex:4: (module)
iex> Hrmm.$someFun$()
** (SyntaxError) iex:4: unexpected token: "$" (column 6, codepoint U+0024)
iex> Hrmm.:$someFun$()
** (SyntaxError) iex:4: unexpected token: ":" (column 6, codepoint U+003A)
iex> Hrmm.:"$someFun$"()
** (SyntaxError) iex:4: syntax error before: "$someFun$"
This is the first major compatibility issue I’ve run across, and it seems pretty major, how do you work around it other than dropping in to Erlang directly (I.E., how do you stay ‘inside’ of Elixir)?
For note, in erlang you can just do (also wtf syntax coloring in discourse for erlang
…):
% Define a function of any name:
'$blah$'(A) -> A + 42.
% Call a function of any name:
'$blah$'(42).