Regarding the bool to int conversion it is my opinion that a boolean is a type with a domain of {false, true} and I do not have an implicit mapping from {false, true} to int. It is as sensible for false to map to -1 as it is to map to 0. The same holds for true. So I do not want to rely on this arbitrary mapping wich seems more like a coincidence than a resonable idea to me. _Join the equal rights for zero movement_
Why should 0 be false even if it is a completely normal number?
__getitem__ and __setitem__ get their arguments as a tuple. l[2,3] will call l.__getitem__((2,3))
What's wrong with converting a bool to int if it makes the code cleaner and easier to read?
Also, the to_s method should probably be replaced with __str__ instead, wich will be called by str(object). The reason of the usage of these functions to help functional programming, for instance: map(str, someCollection) wich i Ruby would be: someCollection.map{ |obj| obj.to_s }
Comment
Thank you for the hints. I'll try it later today.
Regarding the bool to int conversion it is my opinion that a boolean is a type with a domain of {false, true} and I do not have an implicit mapping from {false, true} to int. It is as sensible for false to map to -1 as it is to map to 0. The same holds for true. So I do not want to rely on this arbitrary mapping wich seems more like a coincidence than a resonable idea to me.
_Join the equal rights for zero movement_
Why should 0 be false even if it is a completely normal number?
regards,
Brian
Parent comment
__getitem__ and __setitem__ get their arguments as a tuple. l[2,3] will call l.__getitem__((2,3)) What's wrong with converting a bool to int if it makes the code cleaner and easier to read? Also, the to_s method should probably be replaced with __str__ instead, wich will be called by str(object). The reason of the usage of these functions to help functional programming, for instance: map(str, someCollection) wich i Ruby would be: someCollection.map{ |obj| obj.to_s }
Replies
Ah, I found a way to solve this in python. I can define a hash indexed by true and false. e.g.
{true: 0, false: 1}[a[i] == b[j]]
does the same as
a[i] == b[j] ? 0 : 1
Nice, that's a trick I haven't used before. I like it. :)