C#3.0 and lambdas

Steven D'Aprano steve at REMOVETHIScyber.com.au
Mon Sep 19 10:13:20 EDT 2005


On Mon, 19 Sep 2005 10:31:48 +0200, Fredrik Lundh wrote:

> meanwhile, over in python-dev land:
> 
>     "Is anyone truly attached to nested tuple function parameters; 'def
>     fxn((a,b)): print a,b'?  /.../
> 
>     Would anyone really throw a huge fit if they went away?  I am willing
>     to write a PEP for their removal in 2.6 with a deprecation in 2.5 if
>     people are up for it."

Consider this:

def func(some_tuple):

How many items should you pass in the tuple? If it takes variable
arguments, then that works, but if you always expect a fixed number, then

def func((x, y))

is more explicit.

The only problem I have is that once you unroll the tuple like that, it is
hardly necessary to pass the argument as a tuple. Why not just pass x and
y as two arguments?

def func(x, y)

I think tuple unrolling would work better if there was a way to refer to
the argument as both a tuple and by the components. Eg, making up a
hypothetical syntax for it:

def func(pt?(x,y)):
    print "Tuple", pt
    print "Items", x, y

Calling func((2,3)) prints:

"Tuple" (2, 3)
"Items" 2 3

Of course, this opens a can of worms, what happens if you pass a mutable
object like a list instead of a tuple or string? 

Still, if Python is eventually to get something static types, it probably
makes sense to keep the def func((x,y)) idiom, because it will come in
handy for ensuring that your sequence arguments have the right number of
items.



-- 
Steven.




More information about the Python-list mailing list