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-20 05:23:59
|
I found a use for Tuples in Ruby, but you will hate it, and frankly I think it's a little weird. However, these kinds of differences in how languages works needs to be allowed. The ruby [] operator can take between 1 and 2 parameters. It's the only language that comes to mind that allows for this kind of syntax. Everyone else either supports slicing or doesn't support multiple indices at all. The semantics of Siop seeing a tuple sent to a subscript operator could be to make a two parameter call. So in Python, you might write: remote_ruby_list[ (4,10) ] # Fetch list starting at 4 and going to 10 Actually this syntax would work in Python, it so happens, as well (creates a tuple): remote_ruby_list[4,10] # Fetch list starting at 4 and going to 10 Similarly, Java: remoteRubyList.get( new Integer{4,10} ); To access a Hash which contains keys that are lists in Python, you would use lists: remote_ruby_hash[ [1,2,3] ] # Fetch item with key [1,2,3]. Of course, Python would interpret accept list and tuples as parameters because it accepts either (whether or not your class can handle lists is another question). This would be a use for having an actual tuple for Ruby, although all those other languages still don't have a use for it. > > 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. > > Kevin |