2019-05-20 | Paul Boddie | raw annotate files changeset graph | Experiment with a temporary attribute on objects. This attribute must be cleared when assignments occur, but it should also be cleared when objects escape from functions (which is not yet done). Since the motivation for marking objects as temporary is their re-use in certain operations, the objective is to avoid objects being used in multiple places and still being marked as temporary and potentially undergoing re-use/mutation. Perhaps the only way of guaranteeing exclusive access to an object is if it is provided as a function result and is immediately passed to a function or operation, with this function either mutating the object or ensuring its direct propagation to another such function. | temporary-object-experiment |
1 a = 4 2 3 def f(x): 4 5 # Test function initialisation (f.$l0). 6 7 def g(y, x=x): 8 9 # Test function initialisation (f.$l0.$l0). 10 11 def h(a, z, x=x, y=y): 12 return x, y, z, a # parameter a overrides global scope 13 14 return h 15 16 return g 17 18 fn = f(1) 19 print fn # __main__.f.$l0 20 print fn(2) # __main__.f.$l0.$l0 21 print fn(2)(5, 3) # (1, 2, 3, 5) 22 print fn(2)(5, 3, 6) # (6, 2, 3, 5) 23 print fn(2)(5, 3, 6, 7) # (6, 7, 3, 5)