Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(at': 0.04; 'allowed.': 0.07; 'discard': 0.07; 'variables': 0.07; 'calls.': 0.09; 'function,': 0.09; 'namespace': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'stack.': 0.09; 'to)': 0.09; 'python': 0.11; 'jan': 0.12; 'stored': 0.12; 'basic.': 0.16; 'called.': 0.16; 'indirect,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:programming': 0.16; 'subject:question.': 0.16; 'wrote:': 0.18; 'mechanism': 0.19; 'stack': 0.19; 'written': 0.21; 'proposed': 0.22; 'header:User-Agent:1': 0.23; 'versions': 0.24; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply- To:1': 0.27; 'idea': 0.28; 'function': 0.29; 'chris': 0.29; 'needed.': 0.30; "skip:' 10": 0.31; 'usually': 0.31; 'overhead': 0.31; 'anyone': 0.31; 'another': 0.32; 'implemented': 0.33; 'actual': 0.34; 'could': 0.34; 'something': 0.35; 'objects': 0.35; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'functions.': 0.36; 'words,': 0.36; 'thank': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'space': 0.40; 'how': 0.40; 'most': 0.60; 'matter': 0.61; 'first': 0.61; 'times': 0.62; 'teaching': 0.64; 'thomas': 0.65; 'direct': 0.67; 'believe': 0.68; 'paper': 0.75; 'received:fios.verizon.net': 0.84; 'recursion,': 0.84; 'sheet': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Generarl programming question. Date: Sat, 11 Apr 2015 14:47:51 -0400 References: <12030326.cc9aoE7jz1@PointedEars.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-98-114-97-173.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 In-Reply-To: <12030326.cc9aoE7jz1@PointedEars.de> 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1428778121 news.xs4all.nl 2931 [2001:888:2000:d::a6]:42099 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:88836 On 4/11/2015 12:23 PM, Thomas 'PointedEars' Lahn wrote: > Chris Angelico wrote: > >> The 'x' inside each function is completely separate, no matter how >> many times they get called. They're usually stored on something called >> a "call stack" - you put another sheet of paper on top of the stack >> every time you call a function, local variables are all written on >> that paper, and when you return from a function, you discard the top >> sheet and see what's underneath. > > Thank you for that description; I shall use it from now on when teaching > laymen about the call stack. What Chris is describing is one local namespace (sheet of paper) per function *call*. In early Fortran (at least the first version I used), there was one local namespace (sheet) per *function*. The call stack was a stack of (pointers to) functions. While a function object was in use (after a call, before the return), it could not be called again. In other words, recursion, direct or indirect, was not allowed. I believe the same was (is?) true of some versions of BASIC. It has been proposed that Python use a hybrid model. Function objects would have space for local variables for the first call, but there would also be a mechanism to allocate additional 'sheets' for recursive calls. The idea is that most functions are not called recursively, so the overhead of allocating and freeing the per-call space is usually not needed. I do not believe that anyone has implemented the idea to test feasibility and the actual speedup in relation to the additional complexity. -- Terry Jan Reedy