One thing Python lacks is the ability to use preceding arguments in defaults, e.g. you cannot do this:
def f(a=3, b=a+1): return (a + b) / 2 NameError: name 'a' is not defined
f(b=3)
Common Lisp does this right.
def f(a=3, b=None): b = b or a+1 # or use a more explicit version return (a + b) / 2
- "Let B be one greater than A unless otherwise specified."
- "We have no default value for B. If B has a value, then let B be equal to that value. If B does not have a value, then let B be one greater than A."
I think Python's behaviour is confusing and basically never what anyone actually wants. Regardless of whether or not you can use other params in defaults, the defaults should be evaluated on each call.
One thing Python lacks is the ability to use preceding arguments in defaults, e.g. you cannot do this:
Oops.