Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'syntax': 0.03; 'calls.': 0.07; 'decorator': 0.07; '**kwargs)': 0.09; '**kwargs):': 0.09; '40,': 0.09; 'arg': 0.09; 'commonly': 0.09; 'differing': 0.09; 'positional': 0.09; 'threshold': 0.09; 'useless': 0.09; 'def': 0.10; 'useful,': 0.13; 'sat,': 0.15; '"..."': 0.16; '...,': 0.16; '36,': 0.16; '37,': 0.16; '39,': 0.16; '42,': 0.16; 'argument.': 0.16; 'cases:': 0.16; 'ellipsis': 0.16; 'f(arg):': 0.16; 'sugar': 0.16; 'syntactic': 0.16; '\xa0print': 0.16; 'wrote:': 0.17; 'stefan': 0.17; 'jan': 0.18; 'code,': 0.18; 'email addr:gmail.com>': 0.20; 'to:name:python- list@python.org': 0.20; 'written': 0.20; 'all,': 0.21; 'example': 0.23; 'thus': 0.24; 'idea': 0.24; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'change,': 0.27; 'expansion': 0.27; 'skip:@ 10': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'subject:list': 0.28; 'closer': 0.29; 'url:mailman': 0.29; '8bit%:5': 0.29; 'skip:& 10': 0.29; 'function': 0.30; 'implement': 0.32; 'url:python': 0.32; 'could': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'like:': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; 'url:org': 0.36; '12,': 0.36; 'should': 0.36; 'turn': 0.36; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'easily': 0.39; 'little': 0.39; 'header:Received:5': 0.40; 'url:mail': 0.40; 'think': 0.40; 'your': 0.60; 'easy': 0.60; 'relatively': 0.62; 'skip:n 10': 0.63; 'making': 0.64; 'dear': 0.66; '2013': 0.84 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:x-gm-message-state; bh=jmcbr0LvOMqE6a8/rxNeYsEcmj2ECvDcbb2ZcYFFMkU=; b=WfQcwNkfrisK/rAsXMTXmM6bPFo4diW0D+4TSfNPLbgF2DDqdANZiwY0lf7ZxRX0ad g0BwWAh+DX0XxCZNmRCwvl+kTNzGK9OGne0RwB/sabFwh9h18+plR41D/pJdj+QOb4iL S03KAd8LGhtpMZagIVoTwaJcn3K5pCz6DOrjFFqhk0bGuc0G3VttGput9N+VFFsFZJTj dm+ACOtE2Bvq/u5agsyeY26Thr9eXVazlX1wyWG9xl4nKkrKds/Dvv7vebZwlrjoi4a1 Je+j4GF1IneR50wgCePyTvmXBnD58bBUDvNZosffkR/hshTK99ENoML6SLG7fDaezrAZ Z5MQ== MIME-Version: 1.0 In-Reply-To: References: From: Chris Kaynor Date: Mon, 14 Jan 2013 09:38:23 -0800 Subject: Re: proposal: Ellipsis in argument list To: "python-list@python.org" Content-Type: multipart/alternative; boundary=0016e6d2755fd9db6b04d3431d44 X-Gm-Message-State: ALoCoQksGH9AK394gqxgkXONik2JGb5Sl5/+qODlJOZ5p97UYTOil7L5vkSHdifvcK/peUHbwF3H X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 143 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358185133 news.xs4all.nl 6957 [2001:888:2000:d::a6]:38512 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36805 --0016e6d2755fd9db6b04d3431d44 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Sat, Jan 12, 2013 at 5:30 AM, Szabolcs Bl=E1ga wrote: > Dear All, > > I have an idea that the Ellipsis object could be used in function calls. > The "..." syntax should automagically turn into an Ellipsis positional > argument. > > def f(*args): > ext_args =3D [] > for i, a in enumerate(args): > if a is Ellipsis: > ext_args.extend([x for x in range(args[i-1]-1, args[i+1])]) > else: > ext_args.append(a) > return ext_args > > Calling it for the above example specifically: > > >>>f(34, ..., 43) > [34, 35, 36, 37, 38, 39, 40, 41, 42, 43] > > That might be useless or someone might say it is confusing, but I think i= t > would be relatively easy to implement and a nice little syntactic "sugar"= . > > The basis for adding syntactic sugar is closer to: Is this something that cannot be done clearly without the change, and is commonly useful? Also, as Stefan showed, this is already valid syntax with differing meaning, and thus could break existing code, making the threshold for adding it even harder. This change doesn't seem to useful, and can be easily done already: f(range(34, 43)) Additionally, a decorator could easily be written to do this if you find this is a pattern you commonly use for specific functions (untested), or you can use your expansion function for other cases: def ellipsisExpand(func): def newFunc(*args, **kwargs): ext_args =3D [] for i, a in enumerate(args): if a is Ellipsis: ext_args.extend([x for x in range(args[i-1]-1, args[i+1])]) else: ext_args.append(a) return func(*ext_args, **kwargs) Then, you use this like: @ellipsisExpand def f(arg): print arg > Best regards, > > Szabolcs Blaga > > -- > http://mail.python.org/mailman/listinfo/python-list > > --0016e6d2755fd9db6b04d3431d44 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Sat, Jan 12, 2013 at 5:30 AM, Szabolcs Bl=E1ga <szabolcs.blaga@gmail.com> wrote:
Dear All,

I have an idea that the Ellip= sis object could be used in function calls. The "..." syntax shou= ld automagically turn into an Ellipsis positional argument.

def f(*args):
=A0 ext_args =3D []
=A0 for i, a in enumerate(args):
=A0 =A0 if a is Ellipsis:
=A0 =A0 =A0 ext_args.extend([x for x= in range(args[i-1]-1, args[i+1])])
=A0 =A0 else:
=A0 = =A0 =A0 ext_args.append(a)
=A0 return ext_args

Calling it for the above = example specifically:

>>>f(34, ..., 43)
[34, 35, 36, 37, 38, 39, 40, 41, 42, 43]

That might be useless or someone might say it is confusing, but I think it = would be relatively easy to implement and a nice little syntactic "sug= ar".


The ba= sis for adding syntactic sugar is closer to: Is this something that cannot = be done clearly without the change, and is commonly useful?
Also, as Stefan showed, this is already valid syntax with differing meaning= , and thus could break existing code, making the threshold for adding it ev= en harder.

This change doesn't= seem to useful, and can be easily done already:
=A0 =A0 f(range(34, 43))

Ad= ditionally, a decorator could easily be written to do this if you find this= is a pattern you commonly use for specific functions (untested), or you ca= n use your expansion function for other cases:

def ellipsisExpand(func):
= =A0 def newFunc(*args, **kwargs):
=A0 =A0 ext_args =3D= []
=A0 =A0 for i, a in enumerate(args):
=A0 =A0 =A0 if= a is Ellipsis:
=A0 =A0 =A0 =A0 ext_args.extend([x for x in range(args[i-1]-1, args[i+= 1])])
=A0 =A0 =A0 else:
=A0 =A0 =A0 =A0 ext_args.append= (a)
=A0 =A0 return func(*ext_args, **kwargs)

=
Then, you use this like:
@ellipsisExpand
def f(arg):
=A0 = =A0print arg

=A0
Best regards,

Szabolcs Blaga

--
http://mail.python.org/mailman/listinfo/python-list


--0016e6d2755fd9db6b04d3431d44--