Comment

Sebastian

__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 }

Parent comment

Brian

Sebastian: Thank you for the clarifications. Would you mind showing how to do the __getitem__ an __setitem__ thingie. I remember I tried it but could not get it to work with multiple arguments. Regarding join, thank you I learned something new. It seems it's a matter of perspective. Though I'd express array.join(string) as "ask the array to join itself using string as a seperator" ;-) The int(not a[i] == b[j]) though is something I'll never allow in my programs. I like to distinguish between false, true and numbers and the above is certainly golfish. regards, Brian

Replies

brian

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

Brian

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

Sebastian

Nice, that's a trick I haven't used before. I like it. :)