[elixir-core:6176] Re: Proposal: guard-safe modulo function `mod(a, n)`

2016-08-08 Thread Wiebe-Marten Wijnja
All right! It took most of today, but I've solved the problem! *Problem:* Elixir does not have a (guard-safe) Floored Modulo Remainder function `mod`. *Proposed solution:* Implement with floored division, as follows: mod(a, n) === a - (n * floor_div(a, n)) *Subproblem:* Elixir does not have

[elixir-core:6175] Re: Kernel.compare/2 and Comparable protocol

2016-08-08 Thread Wiebe-Marten Wijnja
> > why not use *-1, 0, 1* instead of* :lt, :eq, :gt*? > Saying that using atoms is the Elixir equivalent of Haskell's Ord does not make a lot of sense, I believe; Elixir does not have static types, so any agreed-upon triple of values is equally valid to represent the different possibilities

Re: [elixir-core:6173] Re: Proposal: guard-safe modulo function `mod(a, n)`

2016-08-08 Thread eksperimental
I have tried to implement a guard safe version this in the past, to no avail. The limitation that I can remember was to not to be able to use a conditional in the guards, which let me to create conditionals using boolean operators.. it didn't work. I will be happy to see a solution. On Mon, 8

Re: [elixir-core:6172] Kernel.compare/2 and Comparable protocol

2016-08-08 Thread Michał Muskała
> On 08 Aug 2016, at 03:36, Paul Schoenfelder > wrote: > > Just my two cents, but why would this function return atoms instead of -1, 0, > 1? Then it works easily with sorting functions, and is consistent with > compare implementations in other languages. There’s

[elixir-core:6172] Re: Proposal: guard-safe modulo function `mod(a, n)`

2016-08-08 Thread Wiebe-Marten Wijnja
I have been fiddling around with this for quite some time. Other than I thought, `div` also uses truncated division. (It makes sense, as it complements `rem`). This makes above implementation moot. To be able to create `mod`, we need a floored division. I have not yet found a way to do this

Re: [elixir-core:6170] Proposal: guard-safe modulo function `mod(a, n)`

2016-08-08 Thread José Valim
Yes, please send a pull request. :) *José Valim* www.plataformatec.com.br Skype: jv.ptec Founder and Director of R On Mon, Aug 8, 2016 at 10:24 AM, Wiebe-Marten Wijnja < w.m.wij...@panache-it.com> wrote: > Elixir has `rem(dividend, divisor)` to calculate the remainder of an > integer

[elixir-core:6170] Proposal: guard-safe modulo function `mod(a, n)`

2016-08-08 Thread Wiebe-Marten Wijnja
Elixir has `rem(dividend, divisor)` to calculate the remainder of an integer division. However, as you probably know, there are different ways to handle remainders with negative numbers: `rem` will take the remainder, but use the sign of the dividend, which means that the following function