Using Erlang libs in Elixir

Serge Aleynikov serge@REDACTED
Thu Sep 2 06:17:53 CEST 2021

For the sake of trying out some ideas, I experimented with doing this:

$ cat > t.erl

-export([t/1, '__info__'/1]).

'__info__'(module)           -> 'Elixir.Temp';
'__info__'(functions)        -> [];
'__info__'(macros)           -> [];
'__info__'(Key = attributes) -> get_module_info(?MODULE, Key);
'__info__'(Key = compile)    -> get_module_info(?MODULE, Key);
'__info__'(Key = md5)        -> get_module_info(?MODULE, Key);
'__info__'(deprecated)       -> [].

t(A) -> A + 1.

$ erlc +debug_info t.erl
$ iex
iex(1)> Temp.t(1)

** (UndefinedFunctionError) function Temp.t/1 is undefined (module Temp is
not available)

This error makes sense - Erlang expects the module name to be 't', and
Elixir expects it
to be 'Elixir.Temp', and the meta information doesn't help much.
If we rename the file to Elixir.Temp.erl and the module name to
then all works well.

Wouldn't it be nice if the Erlang modules allowed aliases so that we could
have a single
module compiled by Erlang to be used in both languages using their native
naming convention?

On Wed, Sep 1, 2021 at 11:19 PM Dominic Morneau <dmorneau@REDACTED> wrote:

> Telemetry is a good example of an Elixir-friendly Erlang lib, especially
> the docs:
> Some of the general Elixir library guidelines here also apply in Erlang:
> The module name isn't a big deal IMHO, users can just do "alias :erl_lib,
> as: ErlLib" if it bothers them.
> Dominic
> 2021年9月2日(木) 8:04 Serge Aleynikov <serge@REDACTED>:
>> Is there any guideline for making Erlang projects be more Elixir friendly?
>> When developing an Erlang library, it would be nice to have its functions
>> callable from Elixir not like:
>> :erl_lib.some_fun()
>> but rather
>> ErlLib.some_fun()
>> without needing to write a "glue" module compiled into
>> 'Elixir.ErlLib.beam'  that would import all functions from erl_lib and
>> export them locally?
>> Are there more requirements of some metadata (e.g. '__info__'/1) to be
>> included in the Erlang modules?
>> Regards,
>> Serge
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the erlang-questions mailing list