Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #94076
| References | <mailman.617.1437090408.3674.python-list@python.org> <d1060jF9h2gU1@mid.individual.net> |
|---|---|
| Date | 2015-07-19 10:21 +1000 |
| Subject | Re: Proposed keyword to transfer control to another function |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.690.1437265299.3674.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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