Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ken Seehart Newsgroups: comp.lang.python Subject: PEP proposal: sequence expansion support for yield statement: yield * Date: Wed, 20 Apr 2016 19:34:24 +0000 Lines: 37 Message-ID: References: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de ZcKQvHQVnIqW+ThU0T6D5A4wFe0ykP/9DpV1SwWQBaXQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'compiler': 0.05; 'javascript,': 0.07; 'subject:PEP': 0.07; 'compact': 0.09; 'semantics': 0.09; 'syntax': 0.13; 'argument': 0.15; '*sequence': 0.16; 'bytecode': 0.16; 'examples:': 0.16; 'notation,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sequence:': 0.16; 'spacing': 0.16; 'subject:yield': 0.16; 'syntactical': 0.16; 'proposed': 0.20; 'to:name:python-list@python.org': 0.20; '(the': 0.22; 'subject:support': 0.22; 'elements': 0.23; 'implemented': 0.24; "doesn't": 0.26; 'appear': 0.26; 'expansion': 0.27; 'opposed': 0.27; 'sequence': 0.27; 'yield': 0.27; 'notation': 0.29; 'error.': 0.31; 'common': 0.33; 'header:Received:8': 0.35; 'follows:': 0.35; 'propose': 0.35; 'but': 0.36; 'instead': 0.36; 'there': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'url:rec-html40': 0.37; 'charset:us-ascii': 0.37; 'to:addr:python.org': 0.40; 'url:schemas': 0.40; 'url:office': 0.40; 'header:MIME-version:1': 0.60; 'more': 0.63; 'different': 0.63; 'received:203': 0.74; 'or:': 0.84; 'subject: *': 0.84 X-AuditID: cbfec373-f79d26d000001dd9-e7-5717d9c2e8c1 Thread-topic: PEP proposal: sequence expansion support for yield statement: yield * Thread-index: AdGbLlAHXnuclO9DROKn6oI0lt04rgADNpWQ Accept-Language: en-US Content-language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: X-Originating-IP: [105.145.28.155] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrMIsWRmVeSWpSXmKPExsVy+t/hYN1DN8XDDf5+lbc40nqN1YHR48X8 N2wBjFFcNimpOZllqUX6dglcGX9eHGIs+Gha8WJhRAPjNv0uRk4OCQETic8vFjNB2GISF+6t Z+ti5OIQEljCKHFx5zwmCGc+k8TNY61Qmb2MEvc3bmaFcK4xStw5vR+q7DijxN8vB8GGsQkY Svz/PZ8RxBYRMJV4vXI3K4gtLOAn8eL/PhaIeKjEuo43TBC2kcST51+BbA4OFgFVidauYJAw r4CnRPv852BjGIHu+35qDVg5s4C4RHPrTRaIuwUkluw5zwxhi0q8fPyPFWSMhICSxIFL4RDl uRKX715ihxgpKPFj8j2wViEBHYkvR2YzT2AUm4Vk6iwkLbOQtEDEdSQW7P7EBmFrSyxb+JoZ xj5z4DETsvgCRvZVjKKlxckFxUnpuUZ6xYm5xaV56XrJ+bmbGCFRV7yD8cUGq0OMAhyMSjy8 AbXi4UKsiWXFlbmHGCU4mJVEeHuuA4V4UxIrq1KL8uOLSnNSiw8xSnOwKInzprL6hAoJpCeW pGanphakFsFkmTg4pRoYZzpdlp0exaDG+CxJ+OyEK1knjlw7fO1p09qFS5MeT17Nycq8ZI1v LO9yw5WO3QFOUytPxm+PeGGZHpL3dPe2PS4NCju/WM9tm89jUhos9v+6uAfLtuYCmzN1fT8+ +KzLk8p3vuVSZPHc8/rGJQ4OEj+Ofbmfwl4TcEd7n9Ik55snfn+o7/f9rcRSnJFoqMVcVJwI AGoySVW2AgAA X-Mailman-Approved-At: Wed, 20 Apr 2016 15:47:36 -0400 X-Content-Filtered-By: Mailman/MimeDel 2.1.22 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> Xref: csiph.com comp.lang.python:107421 Currently the common pattern for yielding the elements in a sequence is as = follows: for x in sequence: yield x I propose the following replacement (the result would be identical): yield *sequence The semantics are somewhat different from argument expansion (from which th= e syntax is borrowed), but intuitive: yield all of the elements of a sequen= ce (as opposed to yield the sequence as a single item). This doesn't appear= to have any syntactical collisions, as it is currently a syntax error. Motivation: More compact notation, and the compiler can produce more effici= ent bytecode than the former representation (the loop overhead is omitted).= This pattern is very common in recursive generators, so a compact notation= would be nice. Also, there is precedent: the proposed notation is implemented in javascrip= t with identical semantics (though in javascript, the conventional spacing = is different: yield* sequence ). Examples: yield *(1,2,3) ... instead of : yield 1; yield 2; yield 3 ... or: for x in (1,2,3): yield x yield *chain(seq1, seq2) ... instead of : for x in chain(seq1, seq2) yield x ~ Ken Seehart