1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/docs/invocation.txt Mon Apr 21 00:35:18 2008 +0200
1.3 @@ -0,0 +1,48 @@
1.4 +Invocations in classic Python:
1.5 +
1.6 + f(1, 2, 3) # positional
1.7 + f(1, 2) # positional with defaults
1.8 + f(1, 2, c=3) # keywords
1.9 + f(1, c=3) # keywords with defaults
1.10 + f(1, 2, 3, 4) # extra positional arguments
1.11 + f(1, 2, 3, d=4) # extra keyword arguments
1.12 + f(1, 2, *args) # positional bundles (possibly with defaults)
1.13 + f(1, 2, **kw) # keyword bundles (possibly with defaults)
1.14 +
1.15 + Note that f is never fixed before run-time in Python.
1.16 +
1.17 +Comparison to C:
1.18 +
1.19 + f(1, 2, 3) # positional, f known at compile-time
1.20 + f(1, 2, 3) # positional, f is appropriate function pointer
1.21 + # ie. (*f)(A, B, C)
1.22 +
1.23 +Least expensive cases:
1.24 +
1.25 + f(1, 2, 3) # put arguments on stack
1.26 + # if f is not known, add arguments vs. parameters check
1.27 + f(1, 2) # to handle defaults, introduce default "filling" where
1.28 + # not enough arguments are given
1.29 + # if f is not known, this is obviously done at run-time
1.30 +
1.31 +More expensive cases:
1.32 +
1.33 + f(1, 2, c=3) # prepare stack using parameter details
1.34 + # (provided c is a known parameter)
1.35 + # if f is not known, this is obviously done at run-time
1.36 + f(1, c=3) # as with the previous case, with default "filling" done
1.37 + # where not enough arguments are given
1.38 + # if f is not known, this is obviously done at run-time
1.39 + # but with all defaults copied in before keywords are
1.40 + # assigned (since their positions and thus the positions
1.41 + # of missing parameters cannot be known)
1.42 +
1.43 +Awkward cases:
1.44 +
1.45 + f(1, 2, 3, 4) # extra positional arguments
1.46 + f(1, 2, 3, d=4) # extra keyword arguments
1.47 + f(1, 2, *args) # positional bundles (possibly with defaults)
1.48 + f(1, 2, **kw) # keyword bundles (possibly with defaults)
1.49 +
1.50 + These cases require additional structures to be created, potentially at
1.51 + run-time.