Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93987 > unrolled thread
| Started by | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| First post | 2015-07-16 21:44 -0700 |
| Last post | 2015-07-16 21:44 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Proposed keyword to transfer control to another function Ethan Furman <ethan@stoneleaf.us> - 2015-07-16 21:44 -0700
| From | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| Date | 2015-07-16 21:44 -0700 |
| Subject | Re: Proposed keyword to transfer control to another function |
| Message-ID | <mailman.624.1437108272.3674.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web