Re: [Siop-development] How to implement the "Tuple" type in Python
Status: Pre-Alpha
Brought to you by:
slobberchops
From: Rapheal K. <ra...@ma...> - 2006-06-19 20:41:22
|
> On Sat, 2006-06-17 at 18:33 -0700, Rapheal Kaplan wrote: > > I think it makes sense for SIOP to have the notion of a Tuple type. > > Forgive my python ignorance, but what is a tuple and why would I want > one? > > >From a brief glance at a couple python pages, it seems that a tuple is a > > readonly array. Is that really a useful thing? I can't actually think of > any case in my life that I have wanted one. > > I guess the bigger question is whether you plan to support the cool > extra feature of each language, or aim for more of a common subset. > This is a really good question and previously I had dwelled on whether or not to support it. Fact is that many languages will have some sort of differentiation. Pythons reasoning for having tuples vs lists is relatively sound. It has to do with the idea that hashable objects should be immutable. So, for example, this means in Python you can't use a list as a key to a dictionary. You can however, use a Tuple as a key to a dictionary. Ruby allows lists to be used as keys. In Java, a tuple would more likely fit in with an Array (I intend for java.util.List to map to the list type). This would also really means that immutability is not really a requirement for SIOP tuples so much as that they are statically sized lists. The idea would be to supply Ruby with the ability to explicitly create and handle tuples so that they can pass them to other programs. I think that not implementing Tuples in Ruby might be ok (as in, if it receives a Tuple instance it simply returns a list and doesn't care about it's original type). However, there really does need to be a way for Ruby to indicate static sized arrays to a number of other programming languages. Again, maybe it could be handled in the casting Level rather than by implementing a Tuple object. Either way, the syntax in Ruby is not cumbersome. You can work with lists all the way until you reach a method that requires it: my_list = [ 1,2,3,4 ] ... do stuff with list, make it bigger, etc... python_object.needs_a_tuple( Siop.Tuple(my_list) ) |