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


Groups > comp.lang.python > #93987

Re: Proposed keyword to transfer control to another function

Date 2015-07-16 21:44 -0700
From Ethan Furman <ethan@stoneleaf.us>
Subject Re: Proposed keyword to transfer control to another function
References <CAPTjJmq7_sG+HmMCBPWq2A3GQFPix-OjUTCu+yAmWiJmEFy6PA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.624.1437108272.3674.python-list@python.org> (permalink)

Show all headers | View raw


On 07/16/2015 04:46 PM, Chris Angelico wrote:

> Examples:
>
> # derived from Paul Rubin's example
> def quicksort(array, start, end):
>       midp = partition(array, start, end)
>       if midp <= (start+end)//2:
>          quicksort(array, start, midp)
>          transfer quicksort(array, midp+1, end)
>       else:
>          quicksort(array, midp+1, end)
>          transfer quicksort(array, start, midp)
>
> def count_usage(func):
>      @functools.wraps(func)
>      def wrapper(*args, **kwargs):
>          wrapper.usage += 1
>          transfer func(*args, **kwargs)
>      wrapper.usage = 0
>      return wrapper
>
> Semantics:
> * Evaluate the function and all its arguments, exactly as per a
> current function call.
> * Leaving them on the stack, remove the current call frame and dispose
> of all its objects.
> * Finally, construct a new stack frame for the target function and
> transfer control to it.
>
> In effect, "transfer f()" is equivalent to "return f()", except that
> the current function finishes before the target is entered.

Sounds cool!  Code it up and let us know how it goes.  :)

--
~Ethan~

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


Thread

Re: Proposed keyword to transfer control to another function Ethan Furman <ethan@stoneleaf.us> - 2015-07-16 21:44 -0700

csiph-web