You can use the erlang standard library modules from Elixir, as described here or here. For example:
def random_integer(upper) do
:rand.uniform(upper) # rand is an erlang library
end
You can also add erlang packages to your mix.exs dependencies and use them in your project, as long as these packages are published on hex or on github. You can also use erlang and elixir code together in a project as described here . So yeah, it's perfectly possible to call erlang code from elixir. Vice-versa is also possible, see here for more information: Elixir compiles into BEAM byte code (via Erlang Abstract Format). This means that Elixir code can be called from Erlang and vice versa, without the need to write any bindings.
So from Elixir viewpoint there is no difference between calling Erlang functions and Elixir functions. It is just different atom passed as the receiving module. So you can easily call Erlang modules from Elixir. That mean that without much of the hassle you should be able to compile Erlang AST from within Elixir as well:
No need for any mental translation. Additionally you can without any problems mix Erlang and Elixir code in single Mix project. With tree structure like:
3条答案
按热度按时间evrscar21#
You can use the erlang standard library modules from Elixir, as described here or here.
For example:
You can also add erlang packages to your
mix.exs
dependencies and use them in your project, as long as these packages are published onhex
or on github.You can also use erlang and elixir code together in a project as described here .
So yeah, it's perfectly possible to call erlang code from elixir.
Vice-versa is also possible, see here for more information:
Elixir compiles into BEAM byte code (via Erlang Abstract Format). This means that Elixir code can be called from Erlang and vice versa, without the need to write any bindings.
3yhwsihp2#
Expanding what @zwippie have written:
All remote function calls (by that I mean calling function with explicitly set module/alias) are in form of:
And all "upper case module names" in Elixir are just atoms:
So from Elixir viewpoint there is no difference between calling Erlang functions and Elixir functions. It is just different atom passed as the receiving module.
So you can easily call Erlang modules from Elixir. That mean that without much of the hassle you should be able to compile Erlang AST from within Elixir as well:
No need for any mental translation.
Additionally you can without any problems mix Erlang and Elixir code in single Mix project. With tree structure like:
Where
example.erl
is:And
example.ex
:You can compile project and run it with
And see that Erlang module was successfully compiled and executed from within Elixir code in the same project without problems.
prdp8dxp3#
当从elixir调用erlang代码时,还有一件事需要注意。erlang使用字符串的字符列表。当你调用一个接受字符串的erlang函数时,将字符串转换为字符列表,并将返回的字符串转换为字符串。
示例: