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


Groups > comp.lang.python > #94076

Re: Proposed keyword to transfer control to another function

Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'ideally': 0.04; 'cc:addr :python-list': 0.09; "'return": 0.09; 'attempted': 0.09; 'contexts': 0.09; 'used)': 0.09; 'python': 0.10; 'stack': 0.13; 'def': 0.13; 'missed': 0.15; 'describing': 0.16; 'footing.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'gregory': 0.16; 'hmm.': 0.16; 'illegal,': 0.16; 'logical,': 0.16; 'one-way': 0.16; 'operation.': 0.16; 'wrote:': 0.16; 'obviously': 0.16; 'alternate': 0.18; 'typing': 0.18; 'accepting': 0.18; 'python?': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'function,': 0.22; 'keywords,': 0.22; 'logical': 0.22; 'strip': 0.22; 'am,': 0.23; 'code.': 0.23; '(or': 0.23; 'this:': 0.23; 'implemented': 0.24; 'unix': 0.24; 'written': 0.24; 'header:In-Reply-To:1': 0.24; "i've": 0.25; "doesn't": 0.26; 'chris': 0.26; 'handling': 0.27; 'possibility': 0.27; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'fine': 0.28; 'initial': 0.28; 'back!': 0.29; 'cases.': 0.29; "people's": 0.29; 'pep': 0.29; "i'm": 0.30; 'call.': 0.30; "i'd": 0.31; 'anyone': 0.32; 'another': 0.32; 'maybe': 0.33; 'point': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'clear': 0.35; 'exist': 0.35; 'replace': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'needed': 0.36; 'there': 0.36; 'possible': 0.36; 'keyword': 0.36; 'subject:: ': 0.37; 'turn': 0.37; 'things': 0.38; 'anything': 0.38; 'mean': 0.38; 'why': 0.39; 'whatever': 0.39; "didn't": 0.39; 'rather': 0.39; 'well.': 0.40; 'some': 0.40; 'easy': 0.60; 'term': 0.60; 'your': 0.60; 'personally': 0.61; 'more': 0.63; 'more.': 0.63; 'better.': 0.66; 'jul': 0.72; 'transfer': 0.73; '"yield': 0.84; 'chrisa': 0.84; 'construct': 0.84; 'guido.': 0.84; "it'd": 0.84; 'liking': 0.84; 'presumably': 0.84; 'suspicion': 0.84; 'syntax:': 0.84; 'absolutely': 0.88; 'to:none': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=4yp7hTEUPO3MHcxpOWu6Zn96Mv8cgJ2/WauOibAIPhE=; b=Ek1WOWU8WhVUNLaGP5rMV0X5VJHsRMRFV/+aCX6AyVT8y+Ch1g2VUkRs3ixsFwuiw2 RfgHHM5MizYGsuOte6XUF7ccJnSH930noYhLB5doysaqhEryypenxedEaDx2s6shX3PM PqGoqKzgYVg69SigLpvEUw9/JRyLv/BkcNOXvP2P4ZxlhxrIJi+y2ZzlTY3WCrXzI+5S 9kaGEBjJ0hAbmmjygAfW4fFJyBdqgU2HggZxJsfUjWTPiv+Fzt1r7+oBFJp6zr7ZGZVE svlHl/W3KlK6a3wtLJocwdeM/xG6qv+RYUuzL0oujYuqe1gqqKcIrYyZTDM2AK1IIXoD Ve+w==
MIME-Version 1.0
X-Received by 10.107.132.7 with SMTP id g7mr26817462iod.9.1437265290559; Sat, 18 Jul 2015 17:21:30 -0700 (PDT)
In-Reply-To <d1060jF9h2gU1@mid.individual.net>
References <mailman.617.1437090408.3674.python-list@python.org> <d1060jF9h2gU1@mid.individual.net>
Date Sun, 19 Jul 2015 10:21:30 +1000
Subject Re: Proposed keyword to transfer control to another function
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.690.1437265299.3674.python-list@python.org> (permalink)
Lines 66
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1437265299 news.xs4all.nl 2833 [2001:888:2000:d::a6]:35116
X-Complaints-To abuse@xs4all.nl
Path csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:94076

Show key headers only | View raw


On Sun, Jul 19, 2015 at 9:32 AM, Gregory Ewing
<greg.ewing@canterbury.ac.nz> wrote:
> Chris Angelico wrote:
>>
>> Possible alternate syntax:
>>
>> transfer func[, (arg1, arg2, arg3)[, {'kw1': val1, 'kw2': val2}]]
>>
>> This makes it very clear that this is NOT accepting an arbitrary
>> expression, but MUST be used with a single function and its arguments.
>> Downside: It doesn't look like a function call any more. Upside: It's
>> easy to parse.
>
>
> Personally I'd be fine with your initial syntax, but
> something else might be needed to get it past Guido.
> He didn't like my 'cocall f()' construct in PEP 3152,
> which is syntactically isomorphic to 'transfer f()'.

Maybe it should get written up and rejected, then, to be something to
point to any time anyone advocates TCO.

>> Is there anything that I've missed out in speccing this up? I've a
>> suspicion that this might turn out to be as complicated as 'yield
>> from' in all its handling of edge cases.
>
>
> Presumably it would only work on functions implemented
> in Python? It's no use discarding the Python stack frame
> unless the C recursion in the ceval loop can be avoided
> as well.

Hmm. Conceptually, I'd like it to work like this:

def f(x):
    return from g(x+1)

x = f(3)
# absolutely identical to
x = g(4)

Is it possible to strip away the current Python stack frame and
replace it with a C stack frame? That would be the most logical, if
it's viable. It'd also mean that other Python implementations are all
looking at things on the same footing. Obviously 'return from' (or
whatever keyword is used) would be valid only from a Python function,
but ideally it could chain to a function written in any form.

>> Current candidates:
>> "transfer", "goto", "recurse", and anything else you suggest.
>
>
> Another possibility is "chain", which I've seen in some
> contexts for an sh exec-like operation.

Hah, that brings me back! "Chaining was attempted from a REXX batch
file". I never understood why typing the name of a batch file would do
a one-way chain/exec rather than a more logical call. Unix has that
much better.

Downside: The name "chain" is highly likely to exist in people's code.
I'm liking "return from", as it's currently illegal, uses existing
keywords, and parallels with "yield from". But as a term for
describing what happens, "chain" works well.

ChrisA

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


Thread

Proposed keyword to transfer control to another function Chris Angelico <rosuav@gmail.com> - 2015-07-17 09:46 +1000
  Re: Proposed keyword to transfer control to another function Paul Rubin <no.email@nospam.invalid> - 2015-07-17 20:16 -0700
  Re: Proposed keyword to transfer control to another function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-07-19 11:32 +1200
    Re: Proposed keyword to transfer control to another function Chris Angelico <rosuav@gmail.com> - 2015-07-19 10:21 +1000
    Re: Proposed keyword to transfer control to another function Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-07-19 12:05 -0400
    Re: Proposed keyword to transfer control to another function Chris Angelico <rosuav@gmail.com> - 2015-07-20 02:13 +1000
    Re: Proposed keyword to transfer control to another function MRAB <python@mrabarnett.plus.com> - 2015-07-19 17:24 +0100
    Re: Proposed keyword to transfer control to another function Chris Angelico <rosuav@gmail.com> - 2015-07-20 02:32 +1000
    Re: Proposed keyword to transfer control to another function Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-19 17:41 +0100
    Re: Proposed keyword to transfer control to another function Chris Angelico <rosuav@gmail.com> - 2015-07-20 02:50 +1000
    Re: Proposed keyword to transfer control to another function Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-07-21 19:33 +0200
    Re: Proposed keyword to transfer control to another function Chris Angelico <rosuav@gmail.com> - 2015-07-22 03:38 +1000

csiph-web