1.1 --- a/docs/invocation.txt Sat Jun 07 21:55:24 2008 +0200
1.2 +++ b/docs/invocation.txt Mon Jun 09 21:09:37 2008 +0200
1.3 @@ -11,7 +11,7 @@
1.4
1.5 Note that f is never fixed before run-time in Python.
1.6
1.7 -Comparison to C:
1.8 +Comparison to invocations in C:
1.9
1.10 f(1, 2, 3) # positional, f known at compile-time
1.11 f(1, 2, 3) # positional, f is appropriate function pointer
1.12 @@ -46,3 +46,28 @@
1.13
1.14 These cases require additional structures to be created, potentially at
1.15 run-time.
1.16 +
1.17 +Methods vs. functions:
1.18 +
1.19 + f(obj, 1, 2) # f known as function at compile-time:
1.20 + # f(obj, 1, 2)
1.21 + # f known as C.m at compile-time:
1.22 + # m(obj "assert isinstance(obj, C)", 1, 2)
1.23 + # f not known at compiler-time:
1.24 + # f(<context>, obj, 1, 2) for instance-accessed methods
1.25 + # f(obj, 1, 2) for class-accessed methods
1.26 + # f(obj, 1, 2) for functions
1.27 +
1.28 + (Could either have universal context usage even for functions, which would
1.29 + ignore them, or attempt to remove contexts when functions are called.)
1.30 +
1.31 +Functions as methods:
1.32 +
1.33 + def f(x, y, z): ...
1.34 + class C:
1.35 + m = f
1.36 + c = C()
1.37 + ...
1.38 + f(obj, 1, 2) # no restrictions on obj
1.39 + obj.m(1, 2) # f(obj, 1, 2)
1.40 + C.m(obj, 1, 2) # f(obj "assert isinstance(obj, C)", 1, 2)