Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'wrapper': 0.07; 'derived': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'objects.': 0.09; 'stack,': 0.09; 'stack': 0.13; 'def': 0.13; 'effect,': 0.16; 'examples:': 0.16; 'finishes': 0.16; 'wrote:': 0.16; 'header:In-Reply-To:1': 0.24; 'paul': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; 'chris': 0.26; 'equivalent': 0.27; 'finally,': 0.27; 'start,': 0.27; 'function': 0.28; '**kwargs)': 0.29; '**kwargs):': 0.29; 'arguments,': 0.29; '~ethan~': 0.29; 'code': 0.30; 'call.': 0.30; 'except': 0.34; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'to:addr:python.org': 0.40; 'per': 0.62; 'charset:windows-1252': 0.62; 'leaving': 0.63; 'evaluate': 0.72; 'transfer': 0.73; 'sounds': 0.76; 'construct': 0.84; 'func(*args,': 0.84; 'received:10.1.10': 0.84 Date: Thu, 16 Jul 2015 21:44:30 -0700 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Proposed keyword to transfer control to another function References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437108272 news.xs4all.nl 2892 [2001:888:2000:d::a6]:51547 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93987 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~