2019-05-20 | Paul Boddie | file changeset files shortlog | Demonstrate undesirable side-effects caused by escaping temporary objects. | temporary-object-experiment |
paul@901 | 1 | def f(x): |
paul@901 | 2 | x + 10 |
paul@901 | 3 | return x |
paul@901 | 4 | |
paul@901 | 5 | a = 1.0 |
paul@901 | 6 | b = 2.0 |
paul@901 | 7 | c = 3.0 |
paul@901 | 8 | d = f(a * b) |
paul@901 | 9 | |
paul@901 | 10 | print a * b + c # 5.0 |
paul@901 | 11 | print d + c # 5.0 |
paul@901 | 12 | print d # 2.0 |