f---ing typechecking

Chris Mellon arkanes at gmail.com
Fri Feb 16 11:03:09 EST 2007


On 15 Feb 2007 16:04:14 -0800, Paul McGuire <ptmcg at austin.rr.com> wrote:
> On Feb 15, 5:21 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> > How can there be a structure datatype with an unpredictable
> > number of members?
> >
> > It might have come across as a different question-sorry for any
> > confusion.
>
> This may be where the "tuple is like a struct" analogy isn't so good,
> and "tuple is like a list but immutable" is better.
>
> In both of your examples, the caller of f() sent a fixed list of
> arguments: (1,2,3,4,5,6,7) in the first case and (8,9,10) in the
> second.  Internally I bet the compiler wants to clean up that same
> list of those same args when f() is finished.
>
> Just as a thought experiment, do this for yourself.  Implement f as:
>
>    def f(*args):
>       args = list(args)
>       print args
>
> Now what is it you want to do with args that you can't do with it as a
> tuple?  Do you want some form of communication back to the caller to
> occur, for example?  Maybe some kind of pass-by-ref instead of pass-by-
> value?
>

I wrote code that did exactly this just yesterday. I needed a list
because I wanted to pop arguments off as I consumed them.



More information about the Python-list mailing list