Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Elixir have a Math module?

Tags:

elixir

I was wondering why Elixir doesn't have a Math module.

I understand that we can write this using Erlang math: module:

alias :math, as: Math

but, is it good practice to put that line in our Elixir code?

In iex it seems to work:

iex(1)> alias :math, as: Math
nil
iex(2)> Math.pi()
3.141592653589793
iex(3)> Math.pow(3, 2)
9.0

Alas, it is clear that we cannot get access to documentation in an Elixir way:

iex(4)> h(Math)
:math is an Erlang module and, as such, it does not have Elixir-style docs
like image 464
Chaos Manor Avatar asked Jan 10 '16 13:01

Chaos Manor


2 Answers

but, is it good practice to put that line in our Elixir code?

Yes. In the end, everything is translated into Erlang AST, then compiled into BEAM bytecode. We can't neither deny nor forget the heritage of Erlang in Elixir.

like image 171
Hécate Avatar answered Nov 18 '22 16:11

Hécate


Actually their are plenty of modules currently in erlang that are not present in elixir. Importing all of them would not make much sense, since corresponding erlang modules are available and its quite easy to use them in elixir too.

Also from the docs

Elixir runs in the same virtual machine and is compatible with OTP. Not only that, all the tools and libraries available in the Erlang ecosystem are also available in Elixir, simply because there is no conversion cost from calling Erlang from Elixir and vice-versa.

As for the documentation Elixir is still relatively new, people are working on it. You should have the erlang docs in iex soon. https://github.com/elixir-lang/elixir/issues/3589

like image 7
coderVishal Avatar answered Nov 18 '22 18:11

coderVishal