def my_function(value) when is_integer(value) and value > 0 do
# stuff
end
def my_function(value) when is_positive(value) do
# stuff
end
Integer.is_positive/1 - is_integer(val) and val > 0
Integer.is_negative/1 - is_integer(val) and val < 0
Float.is_positive/1 - is_float(val) and val > 0
Float.is_negative/1 - is_float(val) and val < 0
Kernel.is_positive/1 - is_number(val) and val > 0
Kernel.is_negative/1 - is_number(val) and val < 0
--
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/1d9f2250-9783-4af8-b2bb-9c0379f3b122%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/5cad86c6-4e89-485b-9db9-6a4140c13a63%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/5cad86c6-4e89-485b-9db9-6a4140c13a63%40googlegroups.com.
Elixir isnt statically typed, so at least for me, in general, i dont bother with is_number
I would say no to this one. I think using < is ok. No change necessary.Elixir isnt statically typed, so at least for me, in general, i dont bother with is_number
I lean on a soft no because we’d have to introduce six new functions as you said, plus is_non_negative likely as well
To be clear, those macros are used correctly within Timex, but that pattern is not safe in general, as the arguments are expanded multiple times.
I am still not convinced. Elixir is not a statically typed language. The guard you mention does add some checking, and I wouldnt mind seeing it in Elixir code, but there are so many of these kinds of bugs that still remain ‘unsolved’. The tool to deal with these kinds of bugs are unit tests and dialyzer.
--
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/e7227105-994d-4416-b829-17466b11da00%40googlegroups.com.
I am still not convinced. Elixir is not a statically typed language. The guard you mention does add some checking, and I wouldnt mind seeing it in Elixir code, but there are so many of these kinds of bugs that still remain ‘unsolved’. The tool to deal with these kinds of bugs are unit tests and dialyzer.
I'm not convinced by this idea as well. Why should we have special treatment for lesser/greater than zero, but not for an arbitrary number?
What if I want to allow float AND integer, with the proposed guards it is not possible.
Sure, but saying "we'll never fix them all, so why even try?" is not a good argument. Saying that the solution is unit tests is true for every behaviour; moreover people who don't know this semantic wouldn't test for it.
--
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-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/09ce8113-eb6f-41cd-aa06-9885c79098e4%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAM9Rf%2BJmDDSS3pnMkiPOthE7p6JT%3Dsq4Z__frjzQzH5KOpV8yw%40mail.gmail.com.
The issue with is_positive and is_negative is that they do not really solve the problem. What if you want >= 0? Should we also add is_non_negative and is_non_positive? Or what if you want x >= 2, which is what you would use if you were implementing fibonacci?
On Wed, Nov 22, 2017 at 1:38 PM, Andrea Leopardi <an.le...@gmail.com> wrote:
is_nil/1 is harder to justify for me and I get that it could be implemented as "== nil". As for is_odd/1 and is_even/1, have a look at they implementation. They are implemented in a faster but more obscure way than the simple "rem() == 0" or "rem() == 1".
On Wed, Nov 22, 2017 at 4:22 PM, Isaac Whitfield <i...@whitfin.io> wrote:
I'm curious what you feel about is_odd/1, is_even/1 and is_nil/1?
On Wednesday, November 22, 2017 at 7:20:35 AM UTC-8, Tallak Tveide wrote:Sure, but saying "we'll never fix them all, so why even try?" is not a good argument. Saying that the solution is unit tests is true for every behaviour; moreover people who don't know this semantic wouldn't test for it.I'm arguing that I feel this direction is not what I would expect of Elixir, being a dynamically typed language. I would not trade "bloating the Kernel module" (sorry for not finding a nicer wording, I don't mean to be harsh) for this functionality.
--
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/09ce8113-eb6f-41cd-aa06-9885c79098e4%40googlegroups.com.
--
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 unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/0054998a-61b9-483d-8d5f-c5b52701759b%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/0054998a-61b9-483d-8d5f-c5b52701759b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
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/CAGnRm4%2Bb3rNi1PvP-KyJA_yLGQmDAg4bLZ-_FQ6NYodkPeh%3DAQ%40mail.gmail.com.
The second is even longer.
Wouldn't the outcome `not Integer.is_negative(:atom)` be even worse than what we have now?
Wouldn't the outcome `not Integer.is_negative(:atom)` be even worse than what we have now?What do you mean by worse? If you take the face value of what the macro does "is this a negative integer?", then no, it's not worse.