[Proposal] Elixir.Math module

273 views
Skip to first unread message

Rodney Folz

unread,
Feb 14, 2016, 8:41:33 PM2/14/16
to elixir-lang-core
Hello all,

I would like to propose a new built-in Elixir module, Math.

It is always a slight mental tax to remember which modules I should use Elixir for, and which modules I should call into :erlang for. As I was reading through the Elixir source, I noticed a number of calls in lib/map.ex being `defdelegate`d to erlang directly. This seemed promising, so I wrote up a `defdelegate` shim of the erlang :math module in Elixir -- https://hex.pm/packages/math -- based on the Ruby module of the same name.

You can view the source code for my implementation here: https://github.com/folz/math

Searching through this group for previous proposals regarding an Elixir.Math module turned up nothing for me, so I figured I'd make the proposal and see what you all think.

Best,

Rodney
http://twitter.com/rodneyfolz

eksperimental

unread,
Feb 15, 2016, 12:37:46 AM2/15/16
to elixir-l...@googlegroups.com
I'm +1 for the inclusion of this module, which is an essential module
for many languages (even if it's mostly delegated functions)

Having such module will also encourage other people to contribute more
functions to it, such as the modulo function I wrote some time ago.
https://github.com/eksperimental/experimental_elixir/blob/master/lib/kernel_modulo.ex
https://github.com/eksperimental/experimental_elixir/blob/master/test/kernel_modulo_test.exs

I think log2/1 and log10/1 could be squeezed into log/2

same goes for atan2/2 to be renamed atan/2


On Sun, 14 Feb 2016 17:41:32 -0800 (PST)
Rodney Folz <rod...@rodneyfolz.com> wrote:

> Hello all,
>
> I would like to propose a new built-in Elixir module, Math.
>
> It is always a slight mental tax to remember which modules I should
> use Elixir for, and which modules I should call into :erlang for. As
> I was reading through the Elixir source, I noticed a number of calls
> in lib/map.ex being `defdelegate`d to erlang directly. This seemed
> promising, so I wrote up a `defdelegate` shim of the erlang :math
> module <http://erlang.org/doc/man/math.html> in Elixir --
> https://hex.pm/packages/math -- based on the Ruby module of the same
> name <http://ruby-doc.org/core-2.2.2/Math.html>.

José Valim

unread,
Feb 15, 2016, 4:38:24 AM2/15/16
to elixir-l...@googlegroups.com
Thank you for the proposal. Because the proposed implementation is mostly redirecting to :math functions, we won't accept it. That's not the precedent we want to set. Elixir developers must learn how to leverage the Erlang standard library when necessary. Otherwise this will lead to an influx of unnecessary module wrapping for math, array, queue, digraph, etc.



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/50c07fcf-3d39-4d22-8c20-1d6506a52aa3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ólafur Arason

unread,
Feb 15, 2016, 3:34:24 PM2/15/16
to elixir-lang-core, jose....@plataformatec.com.br
Hi José,

I was wondering if the official documentation could be extended to include
nice things from the Erlang side. I think this is the major concern of most
of the suggestions here. Erlang has good documentation but it has examples
in Erlang.

I don't know if this has been brought up before or don't, it probably has.

We could even do it with a automated system at first that transfers the
erlref format into markdown. All the programming examples could be
translated with my beam_to_ex_ast [1] or Daniels erl2ex[2]. We could
possible have that as permanent solution then people would be
encouraged to improve those documentation where needed.

Regards,
Olaf

Tallak Tveide

unread,
Feb 16, 2016, 1:24:24 PM2/16/16
to elixir-lang-core
I thought about the same thing today. I have read most of the Elixir docs, but have spent little time exploring the aerlang docs. I believe an overview of functionality existing in erlang libraries that should complement Elixir stdlib could be very useful.

On the other hand, i dont think we need to duplicate these documents translated from Erlang to Elixir. I think it would be better to provide some links.

I could help in this matter if there were interest, unfortunately I dont know much about which of the Erlang libraries that are actually useful

José Valim

unread,
Feb 16, 2016, 1:35:19 PM2/16/16
to elixir-l...@googlegroups.com
Would someone like to take a stab at a quick summary of relevant Erlang modules in Erlang's kernel and stdlib applications (i.e. no observer, parser, etc) to host it at our getting started docs? http://elixir-lang.org/getting-started/introduction.html



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

Tallak Tveide

unread,
Feb 17, 2016, 2:11:39 AM2/17/16
to elixir-l...@googlegroups.com
I would like to look at this
> You received this message because you are subscribed to a topic in the
> Google Groups "elixir-lang-core" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/elixir-lang-core/5qxH1apXbzQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> elixir-lang-co...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KCx7fg64LThSWyDAp6G6zkmihi40KSCCbOSK5nVELj9w%40mail.gmail.com.

Adam Lindberg

unread,
Feb 17, 2016, 3:45:41 AM2/17/16
to elixir-l...@googlegroups.com
There are a couple of modules in Elixir that overlap somewhat already (Map, String & Binary, List etc.). What is the policy there? Should overlapping functions be added to those modules or should the Erlang modules be referred to as well?

Here are some modules I’d like to see included in such a list:

• calendar
• crypto
• digraph
• ets
• gb_sets
• gb_trees
• lees
• math
• orddict
• ordsets
• queue
• rand (and not random)
• ssh
• ssl
• wx
• xmerl
• yecc
• zip
• lib

Test and debugging relevant:
• cprof
• dbg
• eprof
• fprof
• observer
• percept


Cheers,
Adam
> To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAHfREDXue3KG%3Dp75vymXhPw%3DzSrPS9yvMQUXcSgyskCnS3DOSQ%40mail.gmail.com.

José Valim

unread,
Feb 17, 2016, 4:28:12 AM2/17/16
to elixir-l...@googlegroups.com
My concern is that, if we are going to list all of these modules, then the list becomes too large and not meaningful. That's why I restricted to only to modules in kernel and stdlib apps.

Also, this is for the getting started guide, so we don't want to overwhelm folks that are in their first week in the language. We need to focus on what is most likely to be used.

Here is a trimmed down version:

* binary
• calendar
• crypto (exceptionally not in stdlib/kernel)
• digraph
• ets
• math

• queue
• rand (and not random)
• zlib (and zip)





José Valim
Skype: jv.ptec
Founder and Director of R&D

Adam Lindberg

unread,
Feb 17, 2016, 4:33:14 AM2/17/16
to elixir-l...@googlegroups.com
Agree about the length. I guess anything that comes up as the first search result in search engines, using “elixir” or “erlang” in front, doesn’t necessarily need to be in that list.

Cheers,
Adam

Augie De Blieck Jr.

unread,
Feb 17, 2016, 10:28:24 AM2/17/16
to elixir-l...@googlegroups.com
Sounds like a great list for a series of blog articles...

Please don't give me ideas... ;-)

-Augie
> To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/808B03CA-A4B4-423D-AAD6-D45E88C1F873%40alind.io.

Tallak Tveide

unread,
Feb 17, 2016, 5:59:36 PM2/17/16
to elixir-l...@googlegroups.com
Here is a first draft. I havent put much thought into the form yet, so
any comments are welcome.

I do perhaps think from the shortlist that a few things are missing;

:erlang._ (for the time functions specifically)
:timer._
:io_list.format (?)

https://github.com/tallakt/elixir-lang.github.com/blob/getting_started_erlang_stdlibs/getting-started/erlang-libraries.markdown
> To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CABYU8zizbbu66Ka2jorbi9XtoDbbhtheVF0D9ffFuc9ihTeXCg%40mail.gmail.com.

José Valim

unread,
Feb 18, 2016, 1:36:09 AM2/18/16
to elixir-l...@googlegroups.com
Nice! Some notes:

* The binary module is useful when you want to work with binary data or other encodings. String is limited to UTF-8 encoded data only.

* The erlang module is too large and we have added the time and timer-related functions to System/Process modules, so I would skip both erlang and timer.

* We could mention io:format(...) too.


José Valim
Skype: jv.ptec
Founder and Director of R&D

Reply all
Reply to author
Forward
Message has been deleted
0 new messages