def a((b,c,d),e):

François Pinard pinard at iro.umontreal.ca
Mon Apr 18 18:32:17 EDT 2005


[Diez B. Roggisch]
> AdSR wrote:

> > It appears that you can specify a function explicitly to take
> > n-tuples as arguments. [...] Has anyone actually used it in real
> > code?

I do not use it often in practice, but sometimes, yes.  If the feature
was not there, it would be easy to do an explicit tuple unpacking from
the argument at the start of the function.  It allows me to spare
inventing a name for the compound formal argument. :-)

> [...] as a limited form of pattern-matching [...]

In one application, written long ago, I had a flurry of functions
kept in a list, which were tried in turn until the call does not
raise an Exception, so indicating a match.  Since then, I used other
means, first hoping to save at least the time it takes for creating a
traceback object (but I did not time it), and later trying to get a
better-than-linear time while trying to find the correct function.

I never considered the feature to be atrocious.  Implicit tuple
unpacking occurs in a few places in Python already, it is only elegant
that it also occurs while functions receive their argument.  The most
useful place for implicit tuple unpacking, in my experience, is likely
at the left of the `in' keyword in `for' statements (and it is even
nicer when one avoids extraneous parentheses).

-- 
François Pinard   http://pinard.progiciels-bpi.ca



More information about the Python-list mailing list