[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jdt-dev] Re: idea for refactoring
|
Gregg G. Wonderly wrote:
Well, python offers a clean solution:
def func (a, b, c=1, d=[], *args, **kw):
...
But, in this case, the following starts to get a bit ugly.
func( 1, 2, d=3, d, d=3 )
is the first 'd=3' an assignment to 'd', or adding '3' to the list of
parameter element 'd'? This is where you have to be a little more careful of
how convenient you think you are making your argument list...
You can assign a parameter only once. To assign multiple values to d, use
func (1,2,d=[3,3])
In your example above, the value of the variable d (in the calling context,
not the parameter d!) gets added to the list args. This is what C calls a
varargs interface.
d = 5
func (1,2,d=3,d,x=4)
would work. args would be [5] and kw = { "x": 4 } ([] is a python list, {} is
a hashmap).
--
Aaron "Optimizer" Digulla a.k.a. Philmann Dark
"It's not the universe that's limited, it's our imagination.
Follow me and I'll show you something beyond the limits."
http://www.philmann-dark.de/