MATH 9 Study Guide - Midterm Guide: Lambda Calculus, Flattening, Selection Sort

101 views36 pages

Document Summary

Math 9 - lecture 9 - mutable vs. immutable review / sorting. The under-the-hood behaviour difference between mutable and immutable objects is very important. Now try doing a similar thing for lists: We explained the reason why: it"s because for lists and other mutable objects, running x = [1,2,3] creates a list [1,2,3] somewhere in memory, and stores, in x the address of that spot. Issuing the command y=x, causes x and y to point to the same object. The value of x didn"t change because a copy of x was made inside the function. In the function, zs is a local variable, and a copy of xs, but not a copy of the list that xs is pointing to. it"s a copy of the address where the list lives. This is why we were able to change xs when we did zs[0]=999 before, because a change in the list that zs and xs are both pointing to was made.