1.1 --- a/docs/invocation.txt Mon May 11 02:17:12 2009 +0200
1.2 +++ b/docs/invocation.txt Sat May 16 01:34:03 2009 +0200
1.3 @@ -40,9 +40,9 @@
1.4 Awkward cases (extra arguments):
1.5
1.6 f(1, 2, 3, 4) # put arguments in frame
1.7 - # if f is not known, add arguments vs. parameters check
1.8 - # target unpacks superfluous arguments from the end of the
1.9 - # frame
1.10 + # if f is not known, add arguments vs. parameters check;
1.11 + # to handle superfluous arguments, make a suitable object
1.12 + # and fill it with all such arguments
1.13
1.14 Very awkward cases:
1.15
1.16 @@ -179,3 +179,52 @@
1.17 # gives context c
1.18 fn(1, 2) # instance context -> no explicit context required
1.19 # context c inserted in call
1.20 +
1.21 +Star parameters are a convenience:
1.22 +
1.23 + max(1, 2, 3) # call to max(*args) where args == (1, 2, 3)
1.24 + max((1, 2, 3)) # but why not just do this instead?
1.25 +
1.26 + One motivation: avoid explicitly making sequences.
1.27 + Opportunity: avoid expensive dynamic allocation of sequences?
1.28 +
1.29 +Star parameters, known callables and sequences:
1.30 +
1.31 + g(1, 2, 3, 4) # g known as function g(a, *args) at compile-time
1.32 +
1.33 + g -> don't get any context information
1.34 + 1 -> argument #1
1.35 + 2 -> reference to sequence containing arguments #2, #3, #4
1.36 +
1.37 + (This according to approach #1 described for unknown callables. With approach
1.38 + #2, normal argument positioning would occur.)
1.39 +
1.40 +Star parameters, unknown callables:
1.41 +
1.42 + g(1, 2, 3, 4) # g not known at compile-time
1.43 +
1.44 + g -> g
1.45 + -> load context for argument #1
1.46 + 1 -> argument #2
1.47 + 2 -> argument #3
1.48 + 3 -> argument #4
1.49 + 4 -> argument #5
1.50 +
1.51 + Then, check the context and shift the frame if necessary (described above).
1.52 +
1.53 + If g has a star parameter - g(a, *args) - then...
1.54 +
1.55 + Approach #1 - move arguments #3, #4, #5 (or shifted to #2, #3, #4) into a
1.56 + sequence, adding a reference to the sequence in their place
1.57 +
1.58 + Approach #2 - maintain special access rules to arguments #3, #4, #5 (perhaps
1.59 + shifted to #2, #3, #4) as a C-like array
1.60 +
1.61 +Tradeoffs for star parameter approaches:
1.62 +
1.63 + Approach #1 - potentially costly at run-time as arguments need moving around,
1.64 + but the arguments would behave normally in functions
1.65 +
1.66 + Approach #2 - need to track usage of the star parameter and to possibly copy
1.67 + its contents if assigned, as well as providing special access
1.68 + mechanisms, but the invocation procedure would be simpler