Thanks Ben and sorry, my example was absoutely horrendous.
I'm trying to "use Foo.Bar" and generate an alias that would be the name of the calling module with the final segment of the module name replaced. e.g. CallerModule.Bar would then contain an "alias CallerModule.Baz".
Muddy waters - perhaps if I rephrase and deal with one part at a time - my naive attempt to dynamically generate an alias is something like the following:
defmodule ElixirAlias.Bar do
alias(String.replace(__MODULE__, "Bar", "Baz") |> String.to_atom)
end
Which results in the error :
** (CompileError) lib/elixir_alias.ex:2: invalid argument for alias, expected a compile time atom or alias, got: {{:., [line: 2], [:erlang, :binary_to_atom]}, [line: 2], [{{:., [line: 2], [String, :replace]}, [line: 2], [ElixirAlias.Bar, "Bar", "Baz"]}, :utf8]}
(stdlib) erl_eval.erl:657: :erl_eval.do_apply/6
I get why it doesn't work - I'm trying to generate an alias via code that isnt executed until run time, but I'm
flummoxed by how to achieve what I want.Ta