Default arguments (was Re: python strings)

Tim Peters (
Mon, 25 Apr 94 16:30:23 -0400

> Actually, there will be a way to do this in 1.0.2 using default
> parameters, more or less:
> i = 5
> def f(i=i):
> print i
> i = 6

Wondering whether it would be a good idea to introduce a syntactic device
to distinguish between default arguments & other uses of initialized
locals. E.g., John started his example with a no-argument "f", and now
has a one-argument f. Perhaps

"def" name "(" argument-list [";" initialized-local-list] "):"

? Say, going _way_ back,

def make_incrementer(inc): # return a function that increments by "inc"
def f(x; n=inc):
return x+n
return f

by3 = make_incrementer(3)

by3() # wrong number of arguments
by3(12) # returns 15
by3(12,-12) # wrong number of arguments, instead of 0

In its favor, it lets you say what you mean more often. Don't know how
much pain it would be, though.

will-live-either-way-ly y'rs - tim