I liked the chapter, though I didn't really see much to talk about with the basic data types. I've done some Ruby coding and I was interested in the idea of Tuples, we don't have those in Ruby. Are they that much faster than Lists?
It mentioned that you could have Tuples of Lists. I assumed that Tuples were something more like C arrays, but how can you have a static array of variable length elements in that kind of scheme?
A tuple is actually a 1-d data structure; it simply stores the memory location of the list. The memory location of the list is immutable, but the contents of the list can change if you have a handle to it.
This is what I expected since many languages function this way- for example, Java also stores memory location for objects, but stores the value for primitive data types. In fact, this property has lead people to call Java "pass by reference" for objects and "pass by value" for primitive types, but technically that phrase has a different meaning, and if I told you that about Python it would make the compiler guys mad at me, see: http://javadude.com/articles/passbyvalue.htm
What is due for this Chapter? Is there an assignment or question set we complete or just read and discuss?
Yup, just read and discuss. As you're doing so you (obviously) should try out what we're learning.
I liked the chapter, though I didn't really see much to talk about with the basic data types. I've done some Ruby coding and I was interested in the idea of Tuples, we don't have those in Ruby. Are they that much faster than Lists?
It mentioned that you could have Tuples of Lists. I assumed that Tuples were something more like C arrays, but how can you have a static array of variable length elements in that kind of scheme?
A tuple is actually a 1-d data structure; it simply stores the memory location of the list. The memory location of the list is immutable, but the contents of the list can change if you have a handle to it.
For example:
sample_list = [1,"2","b"]
sample_tuple = (sample_list,"h",5)
print sample_tuple
print sample_list.pop()
print sample_list
print sample_tuple
gives output
([1, '2', 'b'], 'h', 5)
b
[1, '2']
([1, '2'], 'h', 5)
This does not seem to work for storing more primitive datatypes. For instance, the output of this
some_variable = "fish"
sample_tuple = (some_variable)
print sample_tuple
some_variable = "tuna"
print sample_tuple
is
fish
fish
This is what I expected since many languages function this way- for example, Java also stores memory location for objects, but stores the value for primitive data types. In fact, this property has lead people to call Java "pass by reference" for objects and "pass by value" for primitive types, but technically that phrase has a different meaning, and if I told you that about Python it would make the compiler guys mad at me, see: http://javadude.com/articles/passbyvalue.htm