<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>On Sep 26, 2014, at 17:01, David Mertz <<a href="mailto:mertz@gnosis.cx">mertz@gnosis.cx</a>> wrote:</div><div><br></div><blockquote type="cite"><div><p dir="ltr">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)'.</p></div></blockquote><div>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.</div><div><br></div><div>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?</div><blockquote type="cite"><div>
<p dir="ltr">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.[*]</p></div></blockquote>What about something that's one denornal bit of rounding error away from 0j+1?<div><blockquote type="cite"><div>
<p dir="ltr">[*] 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()'.</p></div></blockquote><div>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.</div><div><br></div><br><blockquote type="cite"><div>
<div class="gmail_quote">On Sep 26, 2014 4:42 PM, "Ben Finney" <<a href="mailto:ben%2Bpython@benfinney.id.au">ben+python@benfinney.id.au</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">David Mertz <<a href="mailto:mertz@gnosis.cx">mertz@gnosis.cx</a>> writes:<br>
<br>
> Isn't the right answer to create an isNatural() function?<br>
<br>
No, the right answer (by PEP 8) is to create an āis_naturalā or<br>
āisnaturalā function :-)<br>
<br>
> Why do we need a type or class rather than just a function?<br>
<br>
Less facetiously: I suspect what is being asked for here is a type which<br>
will *ensure* the values are natural numbers.<br>
<br>
That is a good use of types, IMO: they enforce a domain of values.<br>
<br>
I'm not convinced there is a pressing need to add such a type to the<br>
standard type hierarchy though.<br>
<br>
--<br>
\ āI find the whole business of religion profoundly interesting. |<br>
`\ But it does mystify me that otherwise intelligent people take |<br>
_o__) it seriously.ā āDouglas Adams |<br>
Ben Finney<br>
<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a></blockquote></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Python-ideas mailing list</span><br><span><a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a></span><br><span><a href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a></span><br><span>Code of Conduct: <a href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a></span></div></blockquote></div></body></html>