micropython

docs/invocation.txt

81:5790cc867f93
2008-05-05 Paul Boddie Reverted earlier changes around captured sequences of instructions and support for alternative sequences in certain methods.
     1 Invocations in classic Python:
     2 
     3   f(1, 2, 3)      # positional
     4   f(1, 2)         # positional with defaults
     5   f(1, 2, c=3)    # keywords
     6   f(1, c=3)       # keywords with defaults
     7   f(1, 2, 3, 4)   # extra positional arguments
     8   f(1, 2, 3, d=4) # extra keyword arguments
     9   f(1, 2, *args)  # positional bundles (possibly with defaults)
    10   f(1, 2, **kw)   # keyword bundles (possibly with defaults)
    11 
    12   Note that f is never fixed before run-time in Python.
    13 
    14 Comparison to C:
    15 
    16   f(1, 2, 3)      # positional, f known at compile-time
    17   f(1, 2, 3)      # positional, f is appropriate function pointer
    18                   # ie. (*f)(A, B, C)
    19 
    20 Least expensive cases:
    21 
    22   f(1, 2, 3)      # put arguments on stack
    23                   # if f is not known, add arguments vs. parameters check
    24   f(1, 2)         # to handle defaults, introduce default "filling" where
    25                   # not enough arguments are given
    26                   # if f is not known, this is obviously done at run-time
    27 
    28 More expensive cases:
    29 
    30   f(1, 2, c=3)    # prepare stack using parameter details
    31                   # (provided c is a known parameter)
    32                   # if f is not known, this is obviously done at run-time
    33   f(1, c=3)       # as with the previous case, with default "filling" done
    34                   # where not enough arguments are given
    35                   # if f is not known, this is obviously done at run-time
    36                   # but with all defaults copied in before keywords are
    37                   # assigned (since their positions and thus the positions
    38                   # of missing parameters cannot be known)
    39 
    40 Awkward cases:
    41 
    42   f(1, 2, 3, 4)   # extra positional arguments
    43   f(1, 2, 3, d=4) # extra keyword arguments
    44   f(1, 2, *args)  # positional bundles (possibly with defaults)
    45   f(1, 2, **kw)   # keyword bundles (possibly with defaults)
    46 
    47   These cases require additional structures to be created, potentially at
    48   run-time.