
I wish the `numbers` module would include a `Natural` class that would simply check whether the number is integral and positive.

At first glance it sounds nice and straight forward. But - is a natural positive, or just non-negative? I guess, I'd have to look it up in the docs each time, since either definition is used in lots of places. Also, Natural does not correspond to the python type, but its value. So, you couldn't use it with issubclass. Ram Rachum wrote on 09/26/2014 07:54 PM:

I agree with both the points you raised, they're both disadvantages. The question is whether the uses would be worth these two disadvantages. (`collections.Hashable` also has the second disadvantage you mentioned, and it's still in the stdlib, so there's hope.) On Fri, Sep 26, 2014 at 9:10 PM, Thomas Gläßle <t_glaessle@gmx.de> wrote:

On Sep 26, 2014, at 11:13, Ram Rachum <ram@rachum.com> wrote:
I agree with both the points you raised, they're both disadvantages. The question is whether the uses would be worth these two disadvantages. (`collections.Hashable` also has the second disadvantage you mentioned, and it's still in the stdlib, so there's hope.)
Hashable doesn't have that disadvantage. It checks whether the object's class or any superclass has a __hash__ method. So it's still based on the type, not on the value, and it works as expected with issubclass.

On Sep 26, 2014, at 11:37, Ram Rachum <ram@rachum.com> wrote:
It makes sense if you think of isinstance as a type check, which is what it's supposed to be, rather than a value check. ([3],) is a tuple, and tuples are hashable as a type, even though some specific tuple values might not be. That's exactly why I think you want a type that you can check for Natural, rather than something about the value. That's what isinstance is for, and if you start subverting it to mean other things, that's when it leads to confusion.

Isn't the right answer to create an isNatural() function? Why do we need a type or class rather than just a function? It's not any easier to write 'isinstance(x, Natural)' than it is to write 'isNatural(x)'. On Fri, Sep 26, 2014 at 11:47 AM, Andrew Barnert < abarnert@yahoo.com.dmarc.invalid> wrote:
-- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.

On Fri, Sep 26, 2014 at 3:06 PM, Ram Rachum <ram@rachum.com> wrote:
The only motivations I can think of for making this a type (not that they're good ones) is you could do something like: if isinstance(x, (Natural, Complex, Real)): # elif isinstance(x, Rational): # else: raise ValueError Which is naturally (no pun intended) slightly nicer than if isinstance(x, (Complex, Real)) or isNatural(x): # But really, I agree with David that *if* this were added to the stdlib, it should be as a function. I'm however, unconvinced about the usefulness of having this as a stdlib function (since it should be easy for anyone to define): def isNatural(x): if not isinstance(x, int): return False return x > 0 But here we could argue over whether 0 is Natural or not. Further, this could be rewritten as a one-liner: def isNatural(x): return isinstance(x, int) and x > 0 Which falls under the adage I've oft heard repeated here "Not every one-liner belongs in the standard library"

On Sep 26, 2014, at 13:33, Ethan Furman <ethan@stoneleaf.us> wrote:
Except that 2/3 is a float, and (-1)**.5 is a complex, so it might be perfectly reasonable to expect n5-n7 to be an int. Or maybe Natural(0) or Natural('nan') even, on analogy with 2//3 and whatever float operations return NaN values. As I said in my first message, which one makes more sense probably depends on your application, which is part of why this doesn't belong in the stdlib in the first place... But if it did belong, I'd expect it to act like int and float and underflow to an int. (In which case a type check for Natural might be sensible, but would not often be useful--just like a type check on the result of a/b for integers is sensible but not often useful.)

On Fri, Sep 26, 2014 at 1:27 PM, Ian Cordasco <graffatcolmingov@gmail.com> wrote:
This code seems a bit broken, given:
issubclass(numbers.Rational, numbers.Real) Out[3]: True
def isNatural(x): return isinstance(x, int) and x > 0
I think the original desired behavior is this different one-liner: isNatural = lambda x: int(x)==x and x>0 -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.

isNatural = lambda x: int(x)==x and x>0
Actually, sorry. This is crashy; what I mean is: from numbers import Number isNatural = lambda x: isinstance(x, Number) and int(x)==x and x>0 -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.

David Mertz wrote on 09/26/2014 10:38 PM:
Not sure about the original desired behaviour. I would have guessed the former function as well, as it more closely resembles the isinstance checks with the numbers types: >>> isinstance(1.0, (numbers.Rational, numbers.Integral)) False (one might argue, that 1.0 is a rational value, as is true for most float values, but the type has a different intention)

On Fri, Sep 26, 2014 at 1:57 PM, Thomas Gläßle <t_glaessle@gmx.de> wrote
And more importantly: you wouldn't expect isNatural(3.5) to return True.
That's not a problem with my one-liner, nor Ian's:
However, my correction to avoid crashing on some inputs is still wrong, given:
So I think I really need a couple lines: def isNatural(x): try: return int(x)==x and x>0 except (TypeError, ValueError): return False Of course... if you don't want that behavior, you need to write a different function :-). -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.

On 09/26/2014 02:04 PM, David Mertz wrote:
If we had PEP 463 [1] it could still be a one-liner ;) def is_natural(x): return int(x) == x and x > 0 except TypeError, ValueError: False -- ~Ethan~ [1] http://legacy.python.org/dev/peps/pep-0463/

David Mertz <mertz@gnosis.cx> writes:
Isn't the right answer to create an isNatural() function?
No, the right answer (by PEP 8) is to create an ‘is_natural’ or ‘isnatural’ function :-)
Why do we need a type or class rather than just a function?
Less facetiously: I suspect what is being asked for here is a type which will *ensure* the values are natural numbers. That is a good use of types, IMO: they enforce a domain of values. I'm not convinced there is a pressing need to add such a type to the standard type hierarchy though. -- \ “I find the whole business of religion profoundly interesting. | `\ But it does mystify me that otherwise intelligent people take | _o__) it seriously.” —Douglas Adams | Ben Finney

Well, yeah. I think I lost that discussion in the type annotation thread though. I'd love types to include predicates, but Guido wouldn't 😏. An 'is_natural()' function--by whichever spelling--needs to contain a test which isn't in the type system, whichever result one chooses for 'is_natural(1.0)'. FWIW, I want 'isNatural(0j+1) == True'. But I'm on the losing end of at least three arguments there.... Unless I just roll my own in 5-8 lines of code.[*] [*] I'd want the non-PEP8 spelling because "Natural" in mathematics is always capitalized. That's why we have the built-in 'isGuido(BDFL)' rather than 'is_guido()'. On Sep 26, 2014 4:42 PM, "Ben Finney" <ben+python@benfinney.id.au> wrote:

On Sep 26, 2014, at 17:01, David Mertz <mertz@gnosis.cx> wrote:
Well, yeah. I think I lost that discussion in the type annotation thread though. I'd love types to include predicates, but Guido wouldn't 😏. An 'is_natural()' function--by whichever spelling--needs to contain a test which isn't in the type system, whichever result one chooses for 'is_natural(1.0)'.
It is (or should be) in the type system for any application which has a good use for a natural number type. That's pretty much why Python has classes in the first place. Anyway, the only time I remember ever writing a Natural class in a language that didn't have one was to demonstrate Peano arithmetic, so in Python I'd be inheriting from or encapsulating a frozenset, not an int. I can imagine doing something similar (but more useful) in a symbolic math package. I could even see a Natural type being useful for the same kinds of things C uses unsigned for, but not if it was defined as 1.. instead of 0.. Do people have an actual use case for the type we're talking about here?
FWIW, I want 'isNatural(0j+1) == True'. But I'm on the losing end of at least three arguments there.... Unless I just roll my own in 5-8 lines of code.[*]
What about something that's one denornal bit of rounding error away from 0j+1?
[*] I'd want the non-PEP8 spelling because "Natural" in mathematics is always capitalized. That's why we have the built-in 'isGuido(BDFL)' rather than 'is_guido()'.
Wouldn't is\N{ELEMENT}\N{DOUBLE_N} or something like that (sorry, don't know how to type the actual Unicode on my phone, do know how to look up the right names but too lazy to do so) be better if "in mathematics" is what you really want? In math textbooks and papers, the symbols are usually translated to "is a natural number", not "is a Natural number", so I don't think violating PEP 8 is warranted here.

On Sat, Sep 27, 2014 at 11:13 AM, Andrew Barnert <abarnert@yahoo.com.dmarc.invalid> wrote:
Assuming the characters you're after are U+2208 'ELEMENT OF' and U+2115 'DOUBLE-STRUCK CAPITAL N', your name would be is∈ℕ(). I'd prefer isℕ() for two reasons: firstly, ∈ is a symbol, so it's not valid in a name (though you could open the other can of worms and ask for it to be an operator - then you could spell it "x ∈ ℕ" instead of "isℕ(x)"), and secondly because it's much more common to ask "is natural?" than "is element-of natural?" in function names. But I think this has long gone into crazyland. ChrisA

I've mentioned before that I used vim-cute-python ( https://github.com/ehamberg/vim-cute-python), but customized myself ( http://gnosis.cx/bin/.vim/after/syntax/python.vim). I do not utilize U+2115 'DOUBLE-STRUCK CAPITAL N' anywhere, but it is an elegant character. I use others such as: syntax match pyNiceOperator "\<in\>" conceal cchar=∈ syntax match pyNiceOperator "\<or\>" conceal cchar=∨ syntax match pyNiceOperator "\<and\>" conceal cchar=∧ syntax match pyNiceOperator "\<not in\>" conceal cchar=∉ syntax keyword pyNiceOperator sum conceal cchar=∑ syntax keyword pyNiceBuiltin all conceal cchar=∀ syntax keyword pyNiceBuiltin any conceal cchar=∃ syntax keyword pyNiceStatement int conceal cchar=ℤ syntax keyword pyNiceStatement float conceal cchar=ℝ syntax keyword pyNiceStatement complex conceal cchar=ℂ And contentiously, but it makes sense to me: syntax keyword pyNiceStatement None conceal cchar=ℵ In my mind, since aleph-naught is the first inaccessible cardinal, and 'None' can similarly not be "reached" by operations on values of other types, there is a bit of an analogy. The fact aleph visually resembles capital-N(one) add to the appeal. So onscreen I see something like: for x ∈ it: if isinstance(x, (ℤ, ℝ, ℂ)): y = (x ∨ z) ∧ w I could easily define something to use ℕ but still have the actual source spelling of "Natural", just displayed in a fancy way. On Fri, Sep 26, 2014 at 10:04 PM, Chris Angelico <rosuav@gmail.com> wrote:
-- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.

On Sun, Sep 28, 2014 at 12:13:43AM -0400, random832@fastmail.us wrote:
Guys, a reminder please: Python is a general purpose programming language with a general-purpose notation, not Mathematica. The most specialised the task, or the notation, the less likely it is to belong in Python the language or the standard library. But feel free to create your own libraries, or even your own parser for a mini-language capable of interpreting things like x ∈ ℕ. Or help contribute to Sage. http://www.sagemath.org -- Steven

On Sep 26, 2014, at 10:54, Ram Rachum <ram@rachum.com> wrote:
I wish the `numbers` module would include a `Natural` class that would simply check whether the number is integral and positive.
That's easy to add yourself--and that means nobody else has to be involved in deciding whether "positive" or "nonnegative" is the one true definition for "natural", since you can decide on a per-project basis. Also, it's kind of a strange check. Normally ABCs are used to check a value's _type_, not its _value_. For example, I don't think Integral considers 1.0 an integer, so why should Natural consider it a natural number? It makes more sense to create a concrete natural-number type, which does the appropriate thing in cases like subtraction underflow (is the appropriate thing returning an int instead? raising? depends on your application...), then just make Natural a normal ABC which returns true for any instance of anything that subclasses or registers with Natural, and false for anything else.

At first glance it sounds nice and straight forward. But - is a natural positive, or just non-negative? I guess, I'd have to look it up in the docs each time, since either definition is used in lots of places. Also, Natural does not correspond to the python type, but its value. So, you couldn't use it with issubclass. Ram Rachum wrote on 09/26/2014 07:54 PM:

I agree with both the points you raised, they're both disadvantages. The question is whether the uses would be worth these two disadvantages. (`collections.Hashable` also has the second disadvantage you mentioned, and it's still in the stdlib, so there's hope.) On Fri, Sep 26, 2014 at 9:10 PM, Thomas Gläßle <t_glaessle@gmx.de> wrote:

On Sep 26, 2014, at 11:13, Ram Rachum <ram@rachum.com> wrote:
I agree with both the points you raised, they're both disadvantages. The question is whether the uses would be worth these two disadvantages. (`collections.Hashable` also has the second disadvantage you mentioned, and it's still in the stdlib, so there's hope.)
Hashable doesn't have that disadvantage. It checks whether the object's class or any superclass has a __hash__ method. So it's still based on the type, not on the value, and it works as expected with issubclass.

On Sep 26, 2014, at 11:37, Ram Rachum <ram@rachum.com> wrote:
It makes sense if you think of isinstance as a type check, which is what it's supposed to be, rather than a value check. ([3],) is a tuple, and tuples are hashable as a type, even though some specific tuple values might not be. That's exactly why I think you want a type that you can check for Natural, rather than something about the value. That's what isinstance is for, and if you start subverting it to mean other things, that's when it leads to confusion.

Isn't the right answer to create an isNatural() function? Why do we need a type or class rather than just a function? It's not any easier to write 'isinstance(x, Natural)' than it is to write 'isNatural(x)'. On Fri, Sep 26, 2014 at 11:47 AM, Andrew Barnert < abarnert@yahoo.com.dmarc.invalid> wrote:
-- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.

On Fri, Sep 26, 2014 at 3:06 PM, Ram Rachum <ram@rachum.com> wrote:
The only motivations I can think of for making this a type (not that they're good ones) is you could do something like: if isinstance(x, (Natural, Complex, Real)): # elif isinstance(x, Rational): # else: raise ValueError Which is naturally (no pun intended) slightly nicer than if isinstance(x, (Complex, Real)) or isNatural(x): # But really, I agree with David that *if* this were added to the stdlib, it should be as a function. I'm however, unconvinced about the usefulness of having this as a stdlib function (since it should be easy for anyone to define): def isNatural(x): if not isinstance(x, int): return False return x > 0 But here we could argue over whether 0 is Natural or not. Further, this could be rewritten as a one-liner: def isNatural(x): return isinstance(x, int) and x > 0 Which falls under the adage I've oft heard repeated here "Not every one-liner belongs in the standard library"

On Sep 26, 2014, at 13:33, Ethan Furman <ethan@stoneleaf.us> wrote:
Except that 2/3 is a float, and (-1)**.5 is a complex, so it might be perfectly reasonable to expect n5-n7 to be an int. Or maybe Natural(0) or Natural('nan') even, on analogy with 2//3 and whatever float operations return NaN values. As I said in my first message, which one makes more sense probably depends on your application, which is part of why this doesn't belong in the stdlib in the first place... But if it did belong, I'd expect it to act like int and float and underflow to an int. (In which case a type check for Natural might be sensible, but would not often be useful--just like a type check on the result of a/b for integers is sensible but not often useful.)

On Fri, Sep 26, 2014 at 1:27 PM, Ian Cordasco <graffatcolmingov@gmail.com> wrote:
This code seems a bit broken, given:
issubclass(numbers.Rational, numbers.Real) Out[3]: True
def isNatural(x): return isinstance(x, int) and x > 0
I think the original desired behavior is this different one-liner: isNatural = lambda x: int(x)==x and x>0 -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.

isNatural = lambda x: int(x)==x and x>0
Actually, sorry. This is crashy; what I mean is: from numbers import Number isNatural = lambda x: isinstance(x, Number) and int(x)==x and x>0 -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.

David Mertz wrote on 09/26/2014 10:38 PM:
Not sure about the original desired behaviour. I would have guessed the former function as well, as it more closely resembles the isinstance checks with the numbers types: >>> isinstance(1.0, (numbers.Rational, numbers.Integral)) False (one might argue, that 1.0 is a rational value, as is true for most float values, but the type has a different intention)

On Fri, Sep 26, 2014 at 1:57 PM, Thomas Gläßle <t_glaessle@gmx.de> wrote
And more importantly: you wouldn't expect isNatural(3.5) to return True.
That's not a problem with my one-liner, nor Ian's:
However, my correction to avoid crashing on some inputs is still wrong, given:
So I think I really need a couple lines: def isNatural(x): try: return int(x)==x and x>0 except (TypeError, ValueError): return False Of course... if you don't want that behavior, you need to write a different function :-). -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.

On 09/26/2014 02:04 PM, David Mertz wrote:
If we had PEP 463 [1] it could still be a one-liner ;) def is_natural(x): return int(x) == x and x > 0 except TypeError, ValueError: False -- ~Ethan~ [1] http://legacy.python.org/dev/peps/pep-0463/

David Mertz <mertz@gnosis.cx> writes:
Isn't the right answer to create an isNatural() function?
No, the right answer (by PEP 8) is to create an ‘is_natural’ or ‘isnatural’ function :-)
Why do we need a type or class rather than just a function?
Less facetiously: I suspect what is being asked for here is a type which will *ensure* the values are natural numbers. That is a good use of types, IMO: they enforce a domain of values. I'm not convinced there is a pressing need to add such a type to the standard type hierarchy though. -- \ “I find the whole business of religion profoundly interesting. | `\ But it does mystify me that otherwise intelligent people take | _o__) it seriously.” —Douglas Adams | Ben Finney

Well, yeah. I think I lost that discussion in the type annotation thread though. I'd love types to include predicates, but Guido wouldn't 😏. An 'is_natural()' function--by whichever spelling--needs to contain a test which isn't in the type system, whichever result one chooses for 'is_natural(1.0)'. FWIW, I want 'isNatural(0j+1) == True'. But I'm on the losing end of at least three arguments there.... Unless I just roll my own in 5-8 lines of code.[*] [*] I'd want the non-PEP8 spelling because "Natural" in mathematics is always capitalized. That's why we have the built-in 'isGuido(BDFL)' rather than 'is_guido()'. On Sep 26, 2014 4:42 PM, "Ben Finney" <ben+python@benfinney.id.au> wrote:

On Sep 26, 2014, at 17:01, David Mertz <mertz@gnosis.cx> wrote:
Well, yeah. I think I lost that discussion in the type annotation thread though. I'd love types to include predicates, but Guido wouldn't 😏. An 'is_natural()' function--by whichever spelling--needs to contain a test which isn't in the type system, whichever result one chooses for 'is_natural(1.0)'.
It is (or should be) in the type system for any application which has a good use for a natural number type. That's pretty much why Python has classes in the first place. Anyway, the only time I remember ever writing a Natural class in a language that didn't have one was to demonstrate Peano arithmetic, so in Python I'd be inheriting from or encapsulating a frozenset, not an int. I can imagine doing something similar (but more useful) in a symbolic math package. I could even see a Natural type being useful for the same kinds of things C uses unsigned for, but not if it was defined as 1.. instead of 0.. Do people have an actual use case for the type we're talking about here?
FWIW, I want 'isNatural(0j+1) == True'. But I'm on the losing end of at least three arguments there.... Unless I just roll my own in 5-8 lines of code.[*]
What about something that's one denornal bit of rounding error away from 0j+1?
[*] I'd want the non-PEP8 spelling because "Natural" in mathematics is always capitalized. That's why we have the built-in 'isGuido(BDFL)' rather than 'is_guido()'.
Wouldn't is\N{ELEMENT}\N{DOUBLE_N} or something like that (sorry, don't know how to type the actual Unicode on my phone, do know how to look up the right names but too lazy to do so) be better if "in mathematics" is what you really want? In math textbooks and papers, the symbols are usually translated to "is a natural number", not "is a Natural number", so I don't think violating PEP 8 is warranted here.

On Sat, Sep 27, 2014 at 11:13 AM, Andrew Barnert <abarnert@yahoo.com.dmarc.invalid> wrote:
Assuming the characters you're after are U+2208 'ELEMENT OF' and U+2115 'DOUBLE-STRUCK CAPITAL N', your name would be is∈ℕ(). I'd prefer isℕ() for two reasons: firstly, ∈ is a symbol, so it's not valid in a name (though you could open the other can of worms and ask for it to be an operator - then you could spell it "x ∈ ℕ" instead of "isℕ(x)"), and secondly because it's much more common to ask "is natural?" than "is element-of natural?" in function names. But I think this has long gone into crazyland. ChrisA

I've mentioned before that I used vim-cute-python ( https://github.com/ehamberg/vim-cute-python), but customized myself ( http://gnosis.cx/bin/.vim/after/syntax/python.vim). I do not utilize U+2115 'DOUBLE-STRUCK CAPITAL N' anywhere, but it is an elegant character. I use others such as: syntax match pyNiceOperator "\<in\>" conceal cchar=∈ syntax match pyNiceOperator "\<or\>" conceal cchar=∨ syntax match pyNiceOperator "\<and\>" conceal cchar=∧ syntax match pyNiceOperator "\<not in\>" conceal cchar=∉ syntax keyword pyNiceOperator sum conceal cchar=∑ syntax keyword pyNiceBuiltin all conceal cchar=∀ syntax keyword pyNiceBuiltin any conceal cchar=∃ syntax keyword pyNiceStatement int conceal cchar=ℤ syntax keyword pyNiceStatement float conceal cchar=ℝ syntax keyword pyNiceStatement complex conceal cchar=ℂ And contentiously, but it makes sense to me: syntax keyword pyNiceStatement None conceal cchar=ℵ In my mind, since aleph-naught is the first inaccessible cardinal, and 'None' can similarly not be "reached" by operations on values of other types, there is a bit of an analogy. The fact aleph visually resembles capital-N(one) add to the appeal. So onscreen I see something like: for x ∈ it: if isinstance(x, (ℤ, ℝ, ℂ)): y = (x ∨ z) ∧ w I could easily define something to use ℕ but still have the actual source spelling of "Natural", just displayed in a fancy way. On Fri, Sep 26, 2014 at 10:04 PM, Chris Angelico <rosuav@gmail.com> wrote:
-- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.

On Sun, Sep 28, 2014 at 12:13:43AM -0400, random832@fastmail.us wrote:
Guys, a reminder please: Python is a general purpose programming language with a general-purpose notation, not Mathematica. The most specialised the task, or the notation, the less likely it is to belong in Python the language or the standard library. But feel free to create your own libraries, or even your own parser for a mini-language capable of interpreting things like x ∈ ℕ. Or help contribute to Sage. http://www.sagemath.org -- Steven

On Sep 26, 2014, at 10:54, Ram Rachum <ram@rachum.com> wrote:
I wish the `numbers` module would include a `Natural` class that would simply check whether the number is integral and positive.
That's easy to add yourself--and that means nobody else has to be involved in deciding whether "positive" or "nonnegative" is the one true definition for "natural", since you can decide on a per-project basis. Also, it's kind of a strange check. Normally ABCs are used to check a value's _type_, not its _value_. For example, I don't think Integral considers 1.0 an integer, so why should Natural consider it a natural number? It makes more sense to create a concrete natural-number type, which does the appropriate thing in cases like subtraction underflow (is the appropriate thing returning an int instead? raising? depends on your application...), then just make Natural a normal ABC which returns true for any instance of anything that subclasses or registers with Natural, and false for anything else.
participants (10)
-
Andrew Barnert
-
Ben Finney
-
Chris Angelico
-
David Mertz
-
Ethan Furman
-
Ian Cordasco
-
Ram Rachum
-
random832@fastmail.us
-
Steven D'Aprano
-
Thomas Gläßle