Re: Using Erlang libs in Elixir
Serge Aleynikov <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CANt451nTDhqCoPRNfeZ6SbgCh+YKtgzO61TC+yss074xC_aCgg@mail.gmail.com> |
For the sake of trying out some ideas, I experimented with doing this: $ cat > t.erl -module(t). -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) Temp.t(1) 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 'Elixir.Temp', 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 <[email protected]> wrote: > Telemetry is a good example of an Elixir-friendly Erlang lib, especially > the docs: https://github.com/beam-telemetry/telemetry/ > > Some of the general Elixir library guidelines here also apply in Erlang: > https://hexdocs.pm/elixir/library-guidelines.html#content > > 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 <[email protected]>: > >> 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 >> >