Re: Fwd: Re: Comparisons and sorting of a numeric class....

2015-01-29 Thread Andrew Robinson
On 01/27/2015 02:04 AM, Gregory Ewing wrote: Andrew Robinson wrote: The spelling caveat is great -- and in Python the object named in bool's honor is spelled bool (lowercase too). ;) That doesn't change the fact that the man was called George Boole (not Charles!). If you're going to refer to

Re: Fwd: Re: Comparisons and sorting of a numeric class....

2015-01-27 Thread Gregory Ewing
Andrew Robinson wrote: The spelling caveat is great -- and in Python the object named in bool's honor is spelled bool (lowercase too). ;) That doesn't change the fact that the man was called George Boole (not Charles!). If you're going to refer to him by name, it's only courteous to make some

Re: Fwd: Re: Comparisons and sorting of a numeric class....

2015-01-27 Thread Andrew Robinson
On 01/26/2015 02:22 PM, Ian Kelly wrote: On Jan 26, 2015 6:42 AM, "Andrew Robinson" > wrote: > ... If you're going to descend into insults and name-calling, then I'm not going to waste any more of my time on this thread. I don't believe I've actually, int

Re: Comparisons and sorting of a numeric class....

2015-01-26 Thread Ian Kelly
On Mon, Jan 26, 2015 at 4:47 PM, Andrew Robinson wrote: > Hmmm That's not much different than the tuple object I made as a > container and which Ian complained about. In fact, you did overload the > comparison operators, just like I did... Yeah, I know I said I was done with this thread, bu

Re: Comparisons and sorting of a numeric class....

2015-01-26 Thread Andrew Robinson
Hi, Rob. Sorry I'm so slow in getting back to you there's too much to read and I can't catch up with the backlog. But I wanted to reply to you, at least as I think you made some very good points that make more sense to me than other people's replies. On 01/15/2015 09:54 AM, Rob Gaddi wro

Re: Fwd: Re: Comparisons and sorting of a numeric class....

2015-01-26 Thread Ian Kelly
On Jan 26, 2015 6:42 AM, "Andrew Robinson" wrote: > ... If you're going to descend into insults and name-calling, then I'm not going to waste any more of my time on this thread. The restriction on inheriting from bool isn't likely to change. There have been several suggestions as to how you can d

Re: Fwd: Re: Comparisons and sorting of a numeric class....

2015-01-26 Thread Andrew Robinson
Hi Mark ! I hope you are well, and haven't been injured falling out of your chair laughing. There are probably 12 to 14 emails that I haven't been able to read in my inbox from the python list on the subject of this 'drivel', because I have a real life besides the semi-comedy act that goes on h

Re: Fwd: Re: Comparisons and sorting of a numeric class....

2015-01-26 Thread Mark Lawrence
On 26/01/2015 13:38, Andrew Robinson wrote: *plonk* -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list

Fwd: Re: Comparisons and sorting of a numeric class....

2015-01-26 Thread Andrew Robinson
Original Message Subject:Re: Comparisons and sorting of a numeric class Date: Mon, 26 Jan 2015 05:38:22 -0800 From: Andrew Robinson To: Steven D'Aprano On 01/24/2015 12:27 AM, Steven D'Aprano wrote: Andrew Robinson wrote: But let me exp

Re: Comparisons and sorting of a numeric class....

2015-01-24 Thread Steven D'Aprano
Andrew Robinson wrote: > But let me explain a bit more why I'm picking on Python:  For even if we > set the electronic engineering concerns aside that I've raised (and they > are valid, as OOP is supposed to model reality, not reality be bent to > match OOP) -- People's facile explanations about w

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Chris Angelico
On Sat, Jan 24, 2015 at 4:01 PM, Steven D'Aprano wrote: > # Untested > class B4(IntEnum): > F1 = 0 > F2 = 1 > F3 = 2 > T = 3 > def __bool__(self): > return self is B4.T > def __str__(self): > if self is B4.F1: return "Certainly False" > if self is B

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Steven D'Aprano
Rustom Mody wrote: > On Friday, January 23, 2015 at 10:22:06 PM UTC+5:30, Ian wrote: >> On Fri, Jan 23, 2015 at 8:31 AM, Rustom Mody wrote: >> > Can you tell me what of the following code does not satisfy your >> > requirements? >> > [Needs python 3.4] >> > >> > >> from enum import IntEnum >>

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Rustom Mody
On Friday, January 23, 2015 at 11:35:49 PM UTC+5:30, Ian wrote: > On Fri, Jan 23, 2015 at 10:03 AM, Rustom Mody wrote: > > On Friday, January 23, 2015 at 10:22:06 PM UTC+5:30, Ian wrote: > >> On Fri, Jan 23, 2015 at 8:31 AM, Rustom Mody wrote: > >> > Can you tell me what of the following code does

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Rustom Mody
On Friday, January 23, 2015 at 11:35:49 PM UTC+5:30, Ian wrote: > On Fri, Jan 23, 2015 at 10:03 AM, Rustom Mody wrote: > > On Friday, January 23, 2015 at 10:22:06 PM UTC+5:30, Ian wrote: > >> On Fri, Jan 23, 2015 at 8:31 AM, Rustom Mody wrote: > >> > Can you tell me what of the following code does

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Ian Kelly
On Fri, Jan 23, 2015 at 10:45 AM, Rustom Mody wrote: > No disagreement with the 'hack' > As for "no use case for equal but distinct tokens" - thats a strange > view given this thread If you want equal but distinct, you can give them distinct values and define an __eq__ method that compares them a

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Ian Kelly
On Fri, Jan 23, 2015 at 10:03 AM, Rustom Mody wrote: > On Friday, January 23, 2015 at 10:22:06 PM UTC+5:30, Ian wrote: >> On Fri, Jan 23, 2015 at 8:31 AM, Rustom Mody wrote: >> > Can you tell me what of the following code does not satisfy your >> > requirements? >> > [Needs python 3.4] >> > >> >

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Chris Angelico
On Sat, Jan 24, 2015 at 4:45 AM, Rustom Mody wrote: > No disagreement with the 'hack' > As for "no use case for equal but distinct tokens" - thats a strange > view given this thread Look at it this way: A classic enumeration has no use-case for equal-but-distinct; this thread doesn't disagree wit

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Ian Kelly
On Fri, Jan 23, 2015 at 4:46 AM, Andrew Robinson wrote: > Although, I have to laugh -- Verilog can syntheze a CPU -- implement memory > -- and then load a program and run python on the virtual machine. When the > pentium was first developed, I watched as Intel actually booted up MS-DOS > under u

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Rustom Mody
On Friday, January 23, 2015 at 11:07:48 PM UTC+5:30, Chris Angelico wrote: > On Sat, Jan 24, 2015 at 4:22 AM, Rustom Mody wrote: > > Strikes me that making enumerations is-equal rather than just > > =-equal is a bit heavy-handed and unnecessary > > What do you think? > > *Normal* use of an enumer

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Chris Angelico
On Sat, Jan 24, 2015 at 4:22 AM, Rustom Mody wrote: > Strikes me that making enumerations is-equal rather than just > =-equal is a bit heavy-handed and unnecessary > What do you think? *Normal* use of an enumeration does make sense for them to be identical. Classic use would be like this: class

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Rustom Mody
On Friday, January 23, 2015 at 10:54:06 PM UTC+5:30, Chris Angelico wrote: > On Sat, Jan 24, 2015 at 4:03 AM, Rustom Mody wrote: > > The only workaround I have been able to come up with is: > > > > class B4(IntEnum): > >> F1 = 0 > >> F2 = "" > >> F3 = None > >> T =

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Rustom Mody
On Friday, January 23, 2015 at 10:22:06 PM UTC+5:30, Ian wrote: > On Fri, Jan 23, 2015 at 8:31 AM, Rustom Mody wrote: > > Can you tell me what of the following code does not satisfy your > > requirements? > > [Needs python 3.4] > > > > > from enum import IntEnum > class B4(IntEnum): > >

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Chris Angelico
On Sat, Jan 24, 2015 at 4:03 AM, Rustom Mody wrote: > The only workaround I have been able to come up with is: > > class B4(IntEnum): >> F1 = 0 >> F2 = "" >> F3 = None >> T = 1 > > which is not bad; its ridiculous It's ridiculous because you declared an IntEnum an

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Rustom Mody
On Friday, January 23, 2015 at 10:22:06 PM UTC+5:30, Ian wrote: > On Fri, Jan 23, 2015 at 8:31 AM, Rustom Mody wrote: > > Can you tell me what of the following code does not satisfy your > > requirements? > > [Needs python 3.4] > > > > > from enum import IntEnum > class B4(IntEnum): > >

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Ian Kelly
On Fri, Jan 23, 2015 at 8:31 AM, Rustom Mody wrote: > Can you tell me what of the following code does not satisfy your requirements? > [Needs python 3.4] > > from enum import IntEnum class B4(IntEnum): > F1 = 0 > F2 = 0 > F3 = 0 > T = 1 This strikes me a

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Terry Reedy
On 1/23/2015 6:46 AM, Andrew Robinson wrote: -- because people seem to have a very wrong idea about bool's nature as a dualton being somehow justified solely by the fact that there are only two values in Boolean logic; For, singletons style programming is not justified by the number of values an

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Rustom Mody
On Friday, January 23, 2015 at 5:18:32 PM UTC+5:30, Andrew Robinson wrote: > On 01/15/2015 09:05 AM, Ian Kelly wrote: > > On Thu, Jan 15, 2015 at 12:23 AM, Andrew Robinson wrote: > >> Can you name any other language that *does* allow subclassing of > >> booleans or creation of new boolean values? >

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Mark Lawrence
On 23/01/2015 11:46, Andrew Robinson wrote: Unless I've missed something all you've done is show that you haven't got the faintest idea what you're talking about. Would you either please go away before I die laughing, or tell me where you get the stuff that you're taking. -- My fellow Py

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Chris Angelico
On Fri, Jan 23, 2015 at 10:46 PM, Andrew Robinson wrote: > 4. and he has made bool into the default return type for base type > comparison operators; which means that general programmers expect a bool for > base types and may check for it, even if Python's built in functions do not. I don't get

Re: Comparisons and sorting of a numeric class....

2015-01-23 Thread Andrew Robinson
On 01/15/2015 09:05 AM, Ian Kelly wrote: On Thu, Jan 15, 2015 at 12:23 AM, Andrew Robinson wrote: Can you name any other language that *does* allow subclassing of booleans or creation of new boolean values? Yes. Several off the top of my head -- and I have mentioned these before. They general

Re: Comparisons and sorting of a numeric class....

2015-01-17 Thread Steven D'Aprano
Andrew, sorry for the delay in responding. Your response has been extremely long, so for the interest of brevity I've tried to trim things down to the most pertinent points. Andrew Robinson wrote: [...] > So -- From my perspective, Guido making Python go from an open ended and > permissive use of

Re: Comparisons and sorting of a numeric class....

2015-01-16 Thread Rustom Mody
On Friday, January 16, 2015 at 7:20:13 AM UTC+5:30, Andrew Robinson wrote: Disclaimers 1. Ive not really read the above 542 lines and earlier 2. I am not a fan of OOP Still some thoughts... Electrical engineering (EE) and computer science (CS) may seem related but are quite different disciplin

Re: Comparisons and sorting of a numeric class....

2015-01-16 Thread Gregory Ewing
Andrew Robinson wrote: I never said subclassing bool is the 'only' solution; I have indicated it's a far better solution than many. An assertion with which we very much disagree. I have spent well over twenty years on and off dealing with boolean values that are very often mixed indistingu

Re: Comparisons and sorting of a numeric class....

2015-01-16 Thread Gregory Ewing
Ian Kelly wrote: Wait, are you actually asking why bool is a doubleton? If nobody has answered that, I think probably nobody understood you were asking it, because it shouldn't need to be explained. What does perhaps need explaining is why Python goes out of its way to *enforce* the doubleton-n

Re: Comparisons and sorting of a numeric class....

2015-01-15 Thread Steven D'Aprano
Andrew Robinson wrote: [...much about bools...] I'll get back to that shortly, but for now I just want to make a couple of comments about your HTML email. >> [...] >>> I don't have a setting on my email to turn off html. Sorry. Can't help. >> You are using Thunderbird. You certainly do have suc

Re: Comparisons and sorting of a numeric class....

2015-01-15 Thread Chris Angelico
On Fri, Jan 16, 2015 at 12:45 PM, Andrew Robinson wrote: >>> I don't have a setting on my email to turn off html. Sorry. Can't help. >> >> You are using Thunderbird. You certainly do have such a setting. > > It's nice to know that you read and believe what you see in an email header. > Note: Head

Re: Comparisons and sorting of a numeric class....

2015-01-15 Thread Ian Kelly
On Thu, Jan 15, 2015 at 6:45 PM, Andrew Robinson wrote: > Then I look at python development historically and look at the built in > class's return values for compares; and I notice; they have over time become > more and more tied to the 'type' bool. I expect sometime in the future that > python m

Re: Comparisons and sorting of a numeric class....

2015-01-15 Thread Mark Lawrence
On 16/01/2015 01:45, Andrew Robinson wrote: [snipped as far too long to bother anybody with] I hereby congratulate you on having made it to my Dream Team for having written the longest pile of drivel I've read in the 12 ish years I've been hanging around here. -- My fellow Pythonistas, as

Re: Comparisons and sorting of a numeric class....

2015-01-15 Thread Andrew Robinson
On 01/15/2015 12:41 AM, Steven D'Aprano wrote: On Wed, 14 Jan 2015 23:23:54 -0800, Andrew Robinson wrote: [...] A subclass is generally backward compatible in any event -- as it is built upon a class, so that one can almost always revert to the base class's meaning when desired -- but subclass

Re: Comparisons and sorting of a numeric class....

2015-01-15 Thread Rob Gaddi
On Wed, 14 Jan 2015 23:23:54 -0800 Andrew Robinson wrote: > > > Boolean algebra has two values: true and false, or 1 and 0, or humpty > > and dumpty, or whatever you like to call them. > You're speaking to an Electrical engineer. I know there are 10 kinds of > people, those who know binary and

Re: Comparisons and sorting of a numeric class....

2015-01-15 Thread Ian Kelly
On Thu, Jan 15, 2015 at 12:23 AM, Andrew Robinson wrote: > Can you name any other language that *does* allow subclassing of > booleans or creation of new boolean values? > > Yes. Several off the top of my head -- and I have mentioned these before. > They generally come with the extra subclasses pr

Re: Comparisons and sorting of a numeric class....

2015-01-15 Thread Steven D'Aprano
On Wed, 14 Jan 2015 23:23:54 -0800, Andrew Robinson wrote: [...] > A subclass is generally backward compatible in any event -- as it is > built upon a class, so that one can almost always revert to the base > class's meaning when desired -- but subclassing allows extended meanings > to be carried.

Re: Comparisons and sorting of a numeric class....

2015-01-14 Thread Andrew Robinson
And most of this thread has been nothing more than me asking "why" did Guido say to do that -- and people avoiding answering the question. Wait, are you actually asking why bool is a doubleton? If nobody has answered that, I think probably nobody understood you were asking it, because it shoul

Re: Comparisons and sorting of a numeric class....

2015-01-14 Thread Ian Kelly
On Wed, Jan 14, 2015 at 8:00 PM, Andrew Robinson wrote: > Hi Ian, > On 01/14/2015 12:31 AM, Ian Kelly wrote: > > On Tue, Jan 13, 2015 at 5:12 PM, Andrew Robinson > wrote: > > So -- even a cursory thought shows that the information could be encoded in > a very few lines even without an instance of

Re: Comparisons and sorting of a numeric class....

2015-01-14 Thread Ian Kelly
On Tue, Jan 13, 2015 at 5:12 PM, Andrew Robinson wrote: > So -- even a cursory thought shows that the information could be encoded in > a very few lines even without an instance of a subclass: > > class CAllFalse(): > @classmethod > def __nonzero__(Kls): return False > > class CPartFalse()

Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Andrew Robinson
On 01/12/2015 09:32 PM, Steven D'Aprano wrote: On Mon, 12 Jan 2015 17:59:42 -0800, Andrew Robinson wrote: [...] What I am wanting to know is WHY did Guido think it so important to do that ? Why was he so focused on a strict inability to have any instances of a bool subclass at all -- that he

Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Chris Angelico
On Wed, Jan 14, 2015 at 5:56 AM, Ian Kelly wrote: > On Tue, Jan 13, 2015 at 4:20 AM, Chris Angelico wrote: >> On Tue, Jan 13, 2015 at 10:00 PM, Marko Rauhamaa wrote: >>> The code above, though, shouldn't consume memory since it is a simple >>> tail-recursive loop. >> >> Only if the interpreter c

Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Ian Kelly
On Tue, Jan 13, 2015 at 4:20 AM, Chris Angelico wrote: > On Tue, Jan 13, 2015 at 10:00 PM, Marko Rauhamaa wrote: >> The code above, though, shouldn't consume memory since it is a simple >> tail-recursive loop. > > Only if the interpreter can optimize it away. Bear in mind that it > doesn't _retur

Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Chris Angelico
On Tue, Jan 13, 2015 at 10:00 PM, Marko Rauhamaa wrote: > Terry Reedy : > >> On 1/13/2015 1:13 AM, Chris Angelico wrote: >> def f(): sys.setrecursionlimit(sys.getrecursionlimit()+1) or f() >>> ... >> f() >>> Segmentation fault >>> >>> But otherwise, yes. You shouldn't be able to segfault P

Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Marko Rauhamaa
Terry Reedy : > On 1/13/2015 1:13 AM, Chris Angelico wrote: > def f(): sys.setrecursionlimit(sys.getrecursionlimit()+1) or f() >> ... > f() >> Segmentation fault >> >> But otherwise, yes. You shouldn't be able to segfault Python with >> Python code. > > I would have expected an out-of-memo

Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Chris Angelico
On Tue, Jan 13, 2015 at 9:49 PM, Terry Reedy wrote: > I would have expected an out-of-memory error. If there is not already a > crash issue on the tracker for this, you could add one. It's a stack fault, and it's a documented possibility: https://docs.python.org/2/library/sys.html#sys.setrecurs

Re: Comparisons and sorting of a numeric class....

2015-01-13 Thread Terry Reedy
On 1/13/2015 1:13 AM, Chris Angelico wrote: On Tue, Jan 13, 2015 at 4:32 PM, Steven D'Aprano wrote: Crashing the interpreter from pure Python code is *absolutely not allowed*, so anything which would allow that is forbidden. Except when you willingly shoot yourself in the foot. rosuav@sikors

Re: Comparisons and sorting of a numeric class....

2015-01-12 Thread Ian Kelly
On Mon, Jan 12, 2015 at 9:16 PM, Andrew Robinson wrote: > Instead of pretending what if -- let's actually REPLACE python's built in > bool class with an emulation that ALLOWS subclassing and THEN let's TEST my > hypothesis that the assert statement you gave me can't tell the difference > between b

Re: Comparisons and sorting of a numeric class....

2015-01-12 Thread Chris Angelico
On Tue, Jan 13, 2015 at 4:32 PM, Steven D'Aprano wrote: > Crashing the interpreter from > pure Python code is *absolutely not allowed*, so anything which would > allow that is forbidden. Except when you willingly shoot yourself in the foot. rosuav@sikorsky:~$ python Python 2.7.3 (default, Mar 13

Re: Comparisons and sorting of a numeric class....

2015-01-12 Thread Steven D'Aprano
On Mon, 12 Jan 2015 17:59:42 -0800, Andrew Robinson wrote: [...] > What I am wanting to know is WHY did Guido think it so important to do > that ? Why was he so focused on a strict inability to have any > instances of a bool subclass at all -- that he made a very arbitrary > exception to the gen

Re: Comparisons and sorting of a numeric class....

2015-01-12 Thread Chris Angelico
On Tue, Jan 13, 2015 at 3:57 PM, Steven D'Aprano wrote: > On Tue, 13 Jan 2015 09:35:43 +1100, Chris Angelico wrote: > >> Subclassing bool breaks this invariant, unless you never instantiate the >> subclass, in which case it's completely useless. > > Not necessarily. A class that you never instanti

Re: Comparisons and sorting of a numeric class....

2015-01-12 Thread Steven D'Aprano
On Tue, 13 Jan 2015 09:35:43 +1100, Chris Angelico wrote: > Subclassing bool breaks this invariant, unless you never instantiate the > subclass, in which case it's completely useless. Not necessarily. A class that you never instantiate, but use as an object itself, is another way of implementing

Re: Comparisons and sorting of a numeric class....

2015-01-12 Thread Andrew Robinson
Hmm LOL ... no exception was raised... and we know if the assertion Failed, an exception ought to be raised: The assertion did not fail. There are three parts, and as long as one of them is true, the assertion will pass: 1) x isn't an instance of bool 2) x is the object known as True 3) x i

Re: Comparisons and sorting of a numeric class....

2015-01-12 Thread Chris Angelico
On Tue, Jan 13, 2015 at 12:59 PM, Andrew Robinson wrote: > There is no need to copy data from an initialized superclass instance into a > subclass instance that has no new data, but only rebind -- or add a > binding/proxy object -- to bind the superclass instance to the subclass > methods. > > eg:

Re: Comparisons and sorting of a numeric class....

2015-01-12 Thread Andrew Robinson
On 01/12/2015 02:35 PM, Chris Angelico wrote: On Tue, Jan 13, 2015 at 9:27 AM, Andrew Robinson wrote: Huh? I'm not adding any values when I merely subclass bool ; and even if the subclass could be instantiated -- that's doesn't mean a new value or instance of the base class (bool) must exist.

Re: Comparisons and sorting of a numeric class....

2015-01-12 Thread Chris Angelico
On Tue, Jan 13, 2015 at 9:27 AM, Andrew Robinson wrote: > Huh? I'm not adding any values when I merely subclass bool ; and even if the > subclass could be instantiated -- that's doesn't mean a new value or > instance of the base class (bool) must exist. For I could happily work with > a new subcl

Re: Comparisons and sorting of a numeric class....

2015-01-12 Thread Andrew Robinson
On 01/07/2015 04:04 PM, Ethan Furman wrote: On 01/06/2015 07:37 PM, Andrew Robinson wrote: Explain; How does mere subclassing of bool break the contract that bool has? eg: What method or data would the superclass have that my subclass would not? bool's contract is that there are only two valu

Re: Comparisons and sorting of a numeric class....

2015-01-09 Thread Marko Rauhamaa
Paul Rubin : > Marko's suggestion > > rv = f() > if rv is not None: > return rv > rv = g() > if rv is not None: > return rv > return h() > > seems unspeakably ugly. Well, "unspeakably" is exaggeration IMO. It is a bit lengthy but it is crystal clear. While the

Re: Comparisons and sorting of a numeric class....

2015-01-09 Thread Chris Angelico
On Sat, Jan 10, 2015 at 2:06 AM, Paul Rubin wrote: > Chris Angelico writes: >> for instance, I might have a socket object, and I might not, so I can >> use "if not self.socket: self.connect()" ... > > This sounds like you want a Maybe or Option object. That's exactly what it is - a name that's a

Re: Comparisons and sorting of a numeric class....

2015-01-09 Thread Paul Rubin
Chris Angelico writes: > for instance, I might have a socket object, and I might not, so I can > use "if not self.socket: self.connect()" ... This sounds like you want a Maybe or Option object. Marko's suggestion rv = f() if rv is not None: return rv rv = g() if rv is no

Re: Comparisons and sorting of a numeric class....

2015-01-09 Thread Marko Rauhamaa
Chris Angelico : > I'd have to explicitly check "if self.socket is None:". That is the only way in Python. Wrong: return f() or g() or h() Right: rv = f() if rv is not None: return rv rv = g() if rv is not None: return rv return h() > I'm not advocatin

Re: Comparisons and sorting of a numeric class....

2015-01-09 Thread Chris Angelico
On Fri, Jan 9, 2015 at 11:27 PM, Steven D'Aprano wrote: > Chris Kaynor wrote: > >> Lately, I've been doing quite a bit of work in lua, and many times have >> wished that empty strings, tables, and 0 acted "falsey", but at the same >> time, previously working in Python, there were plenty of times I

Re: Comparisons and sorting of a numeric class....

2015-01-09 Thread Steven D'Aprano
Chris Kaynor wrote: > Lately, I've been doing quite a bit of work in lua, and many times have > wished that empty strings, tables, and 0 acted "falsey", but at the same > time, previously working in Python, there were plenty of times I wished > they acted "truthy". It merely depends on what algori

Re: Comparisons and sorting of a numeric class....

2015-01-08 Thread Marko Rauhamaa
Ian Kelly : >> An advantage of the Scheme way is the chaining of "and" and "or". For >> example, this breaks in Python: >> >>def dir_contents(path): >>if os.path.isdir(path): >>return os.listdir(path) >>return None >> >>def get_choices(): >>return dir_co

Re: Comparisons and sorting of a numeric class....

2015-01-08 Thread Chris Kaynor
On Thu, Jan 8, 2015 at 6:57 AM, Ian Kelly wrote: > On Wed, Jan 7, 2015 at 11:21 PM, Marko Rauhamaa wrote: > > Steven D'Aprano : > > > >> Marko Rauhamaa wrote: > >>> I prefer the Scheme way: > >>>#f is a falsey object > >>>everything else is a truthy object > >> > >> The Scheme way has no

Re: Comparisons and sorting of a numeric class....

2015-01-08 Thread Ian Kelly
On Wed, Jan 7, 2015 at 11:21 PM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >>> I prefer the Scheme way: >>>#f is a falsey object >>>everything else is a truthy object >> >> The Scheme way has no underlying model of what truthiness represents, just >> an arbitrary

Re: Comparisons and sorting of a numeric class....

2015-01-07 Thread Marko Rauhamaa
Steven D'Aprano : > Marko Rauhamaa wrote: >> I prefer the Scheme way: >>#f is a falsey object >>everything else is a truthy object > > The Scheme way has no underlying model of what truthiness represents, just > an arbitrary choice to make a single value have one truthiness, and > everythi

Re: Comparisons and sorting of a numeric class....

2015-01-07 Thread Ethan Furman
On 01/06/2015 07:37 PM, Andrew Robinson wrote: > Explain; How does mere subclassing of bool break the contract that bool has? > eg: What method or data would the superclass have that my subclass would not? bool's contract is that there are only two values (True and False) and only one instance e

Re: Comparisons and sorting of a numeric class....

2015-01-07 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Steven D'Aprano : > >> int 0 is a falsey object >> NoneType None is a falsey object >> str 'hello' is a truthy object >> float 23.0 is a truthy object > > I prefer the Scheme way: > >#f is a falsey object > >everything else is a truthy object The Scheme way ha

Re: Comparisons and sorting of a numeric class....

2015-01-07 Thread Marko Rauhamaa
Steven D'Aprano : > int 0 is a falsey object > NoneType None is a falsey object > str 'hello' is a truthy object > float 23.0 is a truthy object I prefer the Scheme way: #f is a falsey object everything else is a truthy object Marko -- https://mail.python.org/mailman/listinfo/python-li

Re: Comparisons and sorting of a numeric class....

2015-01-07 Thread Chris Angelico
On Wed, Jan 7, 2015 at 7:10 PM, Steven D'Aprano wrote: > ou can make an object which quacks like a bool > (or list, tuple, dict, bool, str...), swims like a bool... Huh. You mean like an Olympic swimming bool? ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Comparisons and sorting of a numeric class....

2015-01-07 Thread Steven D'Aprano
On Tue, 06 Jan 2015 18:01:48 -0800, Andrew Robinson wrote: > but if you can't subclass a built in type -- you can't duck type it -- > for I seem to recall that Python forbids duck typing any built in class > nut not subclasses. I fear that you have completely misunderstood the nature of duck-typi

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Dave Angel
On 01/06/2015 10:37 PM, Andrew Robinson wrote: On 01/06/2015 06:31 PM, Chris Angelico wrote: I already KNOW that 'C++' does have a workaround mechanism, as I've mentioned in a different e-mail, so that there's no reason to instantiate an instance of the subclass of a singleton if you don't w

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Chris Angelico
On Wed, Jan 7, 2015 at 2:39 PM, Dave Angel wrote: > Here we need help from someone who knows more about this particular detail. > I don't know which special methods bool() or not will call, but I'd think it > would be something with a better name than __nonzero__ In Python 2, it is indeed __nonze

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Dave Angel
On 01/06/2015 09:01 PM, Andrew Robinson wrote: On 01/06/2015 06:02 AM, Dave Angel wrote: On 01/06/2015 08:30 AM, Andrew Robinson wrote: So, I'm not sure I can subclass boolean either because that too is a built in class ... but I'm not sure how else to make an object that acts as boolean Fa

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Andrew Robinson
On 01/06/2015 06:31 PM, Chris Angelico wrote: The type check issue is mostly about compatability in the first place ; eg: users typecheck either unintentionally -- (novices syndrome) -- or because they need all the capabilities of a given type, and the only simple way to find out if they are a

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Andrew Robinson
On 01/06/2015 06:34 PM, Terry Reedy wrote: On 1/6/2015 9:01 PM, Andrew Robinson wrote: [snip] There are very few (about 4) builtin classes that cannot be subclassed. bool is one of those few, float is not. Go ahead and subclass it. >>> class F(float): pass >>> F >>> F(2.3) + F(3.3) 5.6

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Terry Reedy
On 1/6/2015 9:01 PM, Andrew Robinson wrote: [snip] There are very few (about 4) builtin classes that cannot be subclassed. bool is one of those few, float is not. Go ahead and subclass it. >>> class F(float): pass >>> F >>> F(2.3) + F(3.3) 5.6 -- Terry Jan Reedy -- https://mail.python.

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Chris Angelico
On Wed, Jan 7, 2015 at 1:20 PM, Andrew Robinson wrote: > Because defining a bunch of special methods defeats the very purpose of > making my class compatible with float variables. > eg: No legacy code would work... > > I know (belatedly) that am going to have to define my own class. > That's prett

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Andrew Robinson
On 01/06/2015 05:35 AM, Chris Angelico wrote: On Wed, Jan 7, 2015 at 12:30 AM, Andrew Robinson wrote: Why this is so important to Guido, I don't know ... but it's making it VERY difficult to add named aliases of False which will still be detected as False and type-checkable as a bool. If my o

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Andrew Robinson
On 01/06/2015 06:02 AM, Dave Angel wrote: On 01/06/2015 08:30 AM, Andrew Robinson wrote: So, I'm not sure I can subclass boolean either because that too is a built in class ... but I'm not sure how else to make an object that acts as boolean False, but can be differentiated from false by the

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Steven D'Aprano
Andrew Robinson wrote: > Hi, > I'm building a custom numeric class that works with values that have > uncertainty and am wanting to make it as compatible with floating point > objects as possible -- so as to be usable in legacy code with minimal > rewites; but but I am having trouble understanding

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Dave Angel
On 01/06/2015 08:30 AM, Andrew Robinson wrote: So, I'm not sure I can subclass boolean either because that too is a built in class ... but I'm not sure how else to make an object that acts as boolean False, but can be differentiated from false by the 'is' operator. It's frustrating -- what go

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Chris Angelico
On Wed, Jan 7, 2015 at 12:30 AM, Andrew Robinson wrote: > Why this is so important to Guido, I don't know ... but it's making it VERY > difficult to add named aliases of False which will still be detected as > False and type-checkable as a bool. If my objects don't type check right -- > they will

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Andrew Robinson
So, I'm not sure I can subclass boolean either because that too is a built in class ... but I'm not sure how else to make an object that acts as boolean False, but can be differentiated from false by the 'is' operator. It's frustrating -- what good is subclassing, if one cant subclass all the

Re: Comparisons and sorting of a numeric class....

2015-01-06 Thread Dave Angel
On 01/06/2015 05:27 AM, Andrew Robinson wrote: Hi, I'm building a custom numeric class that works with values that have uncertainty and am wanting to make it as compatible with floating point objects as possible -- so as to be usable in legacy code with minimal rewites; but but I am having troubl