Lecture 12 Mutable Functions Growth
Lecture 12 - Mutable Functions & Growth
Review:Mutable Values
Review: Mutable Values
Identity vs.Equality in Environment Diagrams ● Review:For assignment statements,evaluate the right side,then assign to the left. ● Copying:When creating a copy,copy exactly what's "in the box". Global frame list 0 Ist1 -2 >>1st1=[0,6,[-2,4]] Ist2 Ist3 s式 >>>1st2=1st1 0 0 >>>1st3=1st1[1:] ist 6
Identity vs. Equality in Environment Diagrams ● Review: For assignment statements, evaluate the right side, then assign to the left. ● Copying: When creating a copy, copy exactly what’s “in the box”. >>> lst1 = [0, 6, [-2, 4]] >>> lst2 = lst1 >>> lst3 = lst1[1:]
Mutating Within Functions >>> def mystery(1st):mutative function 1st.pop() 1st.pop() >>> four=[4,4,4,4] >>mystery(four)) >>four [4,4]
Mutating Within Functions >>> def mystery(lst): # mutative function ... lst.pop() ... lst.pop() >>> four = [4, 4, 4, 4] >>> mystery(four) >>> four [4, 4]
Mutable Functions
Mutable Functions