Closed Maltysen closed 9 years ago
I actually propose getting rid of bools altogether, and only using 1
and 0
.
This is orthogonal to chaining comparison though.
About operator chaining: Can these objects be put in sets? That would be a useful feature. Does repr()
work?
Nice this is a rather dramatic change that has a the potential to cause a lot of issues, I'd like to see / create some test cases.
Oh yeah I forgot about __repr__
. Just had to replace __str__
with repr, now it works.
And yes it can be added to sets. {[qTT
returns {True}
I also added >=
which I forgot last time.
Alright, my tests indicate that repr works, while set doesn't.
More importantly, <0<2 3
throws an error. I would expect it to return True
, like 0<(2<3)
in python.
More generally, h<0 1
doesn't seem to work, nor anything else that treats a bool as 0 or 1.
Ah good point. I need to implement __int__
on it.
Likewise, implementing __hash__
would be good because of:
py pyth.py -c '{[<01<01' {True, True}
I think we'll also need to add the new type to is_num
, and to replace all calls of isinstance(a, int)
with some is_int
method.
This really isn't going to happen anytime soon, especially with Pyth5 going on. Closing so I can do other pulls.
One of the best features of Python is operator chaining. This was obviously missing in Pyth since we evaluate each operator individually. This is my attempt to fix this. Instead of the operator comparisons returning a Boolean, I instead made them return a custom
OpChain
object which contains the chain to expand as a string. When it needs to be used as a boolean, the overloaded__bool__
method evaluates the chain. The__str__
method also returns"True"
or"False"
, making it virtually indistinguishable from a boolean.There is probably a bug with this somewhere, so tell me if you catch one. I have written this for
==
,!=
,<
, and>
so far.