Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17159

Re: Verbose and flexible args and kwargs syntax

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news-transit.tcx.org.uk!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'situation.': 0.05; 'function,': 0.07; 'type,': 0.07; 'typed': 0.07; 'python': 0.08; 'builtin': 0.09; 'immutable': 0.09; 'it;': 0.09; 'iterate': 0.09; 'underlying': 0.09; 'am,': 0.12; 'def': 0.13; 'argument': 0.15; 'attractive.': 0.16; 'constructed': 0.16; 'containers': 0.16; 'head,': 0.16; 'iteration,': 0.16; 'noone': 0.16; 'overly': 0.16; 'perhaps,': 0.16; 'renders': 0.16; 'subject:syntax': 0.16; 'unpack': 0.16; 'unpacking': 0.16; 'cc:addr:python-list': 0.16; 'received:74.125.82.44': 0.16; 'received:mail-ww0-f44.google.com': 0.16; 'syntax': 0.16; 'wrote:': 0.18; 'contribute': 0.18; 'wrap': 0.18; 'cc:no real name:2**0': 0.20; 'programming': 0.21; 'maybe': 0.21; 'input': 0.22; 'so.': 0.22; 'appropriate': 0.22; 'dec': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'knowing': 0.23; 'literal': 0.23; 'cc:2**0': 0.24; 'fine': 0.24; 'index': 0.24; 'specify': 0.24; 'saying': 0.26; 'suggestion': 0.26; 'concern': 0.28; 'bit': 0.28; 'message-id:@mail.gmail.com': 0.28; 'explicit': 0.29; 'yield': 0.29; 'cc:addr:python.org': 0.29; 'class': 0.29; 'seem': 0.30; 'construct': 0.30; 'rarely': 0.30; 'semantics': 0.30; 'functional': 0.31; 'quite': 0.32; 'does': 0.32; 'from,': 0.32; 'list': 0.32; 'objects': 0.32; 'tue,': 0.32; "can't": 0.32; 'rather': 0.33; 'it?': 0.33; 'object': 0.33; 'match': 0.34; 'probably': 0.34; 'it.': 0.34; 'done.': 0.34; 'possible,': 0.34; 'anything': 0.34; 'implies': 0.34; 'latter': 0.34; 'thats': 0.34; 'received:74.125.82': 0.35; 'issue': 0.35; 'copying': 0.35; 'uses': 0.36; 'example,': 0.37; 'before.': 0.37; 'else,': 0.37; 'like,': 0.37; 'sequence': 0.37; 'but': 0.37; 'received:74.125': 0.37; 'received:google.com': 0.37; 'think': 0.37; 'could': 0.37; 'doing': 0.38; 'cases,': 0.38; 'linked': 0.38; 'used,': 0.38; 'several': 0.38; 'should': 0.39; 'being': 0.39; 'why': 0.39; "it's": 0.40; 'happens': 0.40; 'more': 0.61; 'type': 0.61; '2011': 0.61; 'types': 0.61; 'custom': 0.61; 'your': 0.61; 'provided': 0.62; 'efficient': 0.62; 'straight': 0.63; 'ever': 0.65; 'manner': 0.65; 'plus': 0.66; 'want,': 0.71; 'hand,': 0.76; 'lose': 0.84; 'constraint': 0.84; 'fortunately': 0.91; 'uncertain': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=HnEKy+hD8bUR/qv0JekoQhtDiDrJH5Ngtq/AS2hztkA=; b=Fot/T50wI1xdBDqYBBqfNZZNPcw8gvLeVXwCLrHLF8X/0MxIv8uMI5Y1OgwRE1AXub DcSUxUxP8SZwDlH/XsJvB5MC6lE2LK92F4clXl+jqp7+5TDx27l4F9pW76XVe7tIIPrV btjC2U4PNjHQ6TRtPXhtdVkni5Tvj3lpAediE=
MIME-Version 1.0
In-Reply-To <2ff41b2e-90e3-4fae-9951-67bb257ed6ed@m10g2000vbc.googlegroups.com>
References <4EE5C576.2000307@gmail.com> <mailman.3550.1323705162.27778.python-list@python.org> <e31c5737-5514-4031-acdd-4882fe11b867@y7g2000vbe.googlegroups.com> <mailman.3571.1323727128.27778.python-list@python.org> <bdd08297-8fdd-47a2-a435-b12627bd6482@i6g2000vbh.googlegroups.com> <mailman.3574.1323740526.27778.python-list@python.org> <2ff41b2e-90e3-4fae-9951-67bb257ed6ed@m10g2000vbc.googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 13 Dec 2011 11:15:21 -0700
Subject Re: Verbose and flexible args and kwargs syntax
To Eelco <hoogendoorn.eelco@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3610.1323800154.27778.python-list@python.org> (permalink)
Lines 64
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1323800154 news.xs4all.nl 6862 [2001:888:2000:d::a6]:43335
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17159

Show key headers only | View raw


On Tue, Dec 13, 2011 at 1:44 AM, Eelco <hoogendoorn.eelco@gmail.com> wrote:
> 'for i in llist' is not quite going to fly is it? Thats probably the
> reason noone ever uses that construct; its not a proper sequence type.

Not really a problem, because fortunately Python makes it super-easy
to create custom iterators.

def listiter(llist):
    while llist:
        head, llist = llist
        yield head

And you're done.  If you like, you could also wrap this up in a class
with all the sequence-related magic methods you want, although you
lose the simplicity of the literal syntax by doing so.  If this is
rarely used, it is more likely because custom containers are going to
be less efficient than built-ins, but if you want to do functional
programming and are not overly concerned with the speed of iteration,
this is not a bad way to do it.

> Good point. Copy-on-write semantics could be used, but really one
> should have several linked list types reflecting the underlying
> implementations. I would like to have an immutable singly linked list
> builtin of the standard functional type, which you can only unpack
> from one end and renders these issues moot, plus a builtin doubly
> linked list with copy-on-write or copy-on-unpacking semantics.

Copy-on-write could be implemented with any type.  You don't need a
doubly linked list for that.

> We are not talking black magic here; we are talking about an EXPLICIT
> type constraint provided on the very same line.

An explicit type constraint with very different semantics depending on
what particular type you specify and what particular type you're
unpacking from, as I had understood it before.  Now you seem to be
saying that it would always be a copy, but sharing state with
copy-on-write possible, which is a different situation.

> Well perhaps, but not always knowing the type of your objects at write-
> time is inherent to weakly typed languages; this happens all the time.
> Not knowing the type of the sequence to be unpacked is in a sense an
> asset; I can use this construct in a function, and unpack any sequence
> type in a manner appropriate for it. About the result of the unpacking
> I will know just as much as about the input to it; that they are the
> same type.

Just because the issue is inherent doesn't mean we should contribute
to it.  Knowing that an object is an arbitrary sequence is fine if all
you want to do is iterate and index it.  If you want to do anything
else, then it's important to know the type.  The copy-on-write
suggestion does make the type-matching approach a bit more attractive.
 On the other hand, it's also more fragile (what if the type being
unpacked can't be constructed from an iterable?  For example, a
database cursor), so that approach potentially needs additional
error-handling.

Anyway, the more I think about it, that concern is really more of an
issue for straight copying.  One of my pet peeves is that I prefer
list(x) for copying sequences rather than the more common x[::].  The
latter is fine if all I need is an immutable sequence of uncertain
type to iterate and index over -- but then why did I need to make a
copy?  Unpacking implies different use cases, though, and maybe a good
argument can be made for it to match type.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Verbose and flexible args and kwargs syntax Terry Reedy <tjreedy@udel.edu> - 2011-12-12 10:52 -0500
  Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-12 09:12 -0800
    Re: Verbose and flexible args and kwargs syntax Terry Reedy <tjreedy@udel.edu> - 2011-12-12 16:58 -0500
      Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-12 15:40 -0800
        Re: Verbose and flexible args and kwargs syntax Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-12 18:41 -0700
          Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-13 00:44 -0800
            Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-13 01:26 -0800
            Re: Verbose and flexible args and kwargs syntax Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-13 11:15 -0700
              Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-13 12:32 -0800
      Re: Verbose and flexible args and kwargs syntax Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-13 01:34 +0000
    Re: Verbose and flexible args and kwargs syntax alex23 <wuwei23@gmail.com> - 2011-12-12 16:27 -0800
      Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-13 00:30 -0800
        Re: Verbose and flexible args and kwargs syntax Cameron Simpson <cs@zip.com.au> - 2011-12-14 06:11 +1100
          Re: Verbose and flexible args and kwargs syntax Eelco <hoogendoorn.eelco@gmail.com> - 2011-12-13 12:14 -0800

csiph-web