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


Groups > comp.lang.python > #88836

Re: Generarl programming question.

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Generarl programming question.
Date 2015-04-11 14:47 -0400
References <dcb7fd6b-3a96-47e8-91f6-49b21f7bf605@googlegroups.com> <mailman.222.1428765309.12925.python-list@python.org> <12030326.cc9aoE7jz1@PointedEars.de>
Newsgroups comp.lang.python
Message-ID <mailman.227.1428778121.12925.python-list@python.org> (permalink)

Show all headers | View raw


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

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


Thread

Generarl programming question. jonas.thornvall@gmail.com - 2015-04-11 08:00 -0700
  Re: Generarl programming question. Chris Angelico <rosuav@gmail.com> - 2015-04-12 01:15 +1000
    Re: Generarl programming question. jonas.thornvall@gmail.com - 2015-04-11 08:22 -0700
      Re: Generarl programming question. Chris Angelico <rosuav@gmail.com> - 2015-04-12 01:28 +1000
    Re: Generarl programming question. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-11 18:23 +0200
      Re: Generarl programming question. Terry Reedy <tjreedy@udel.edu> - 2015-04-11 14:47 -0400
        Re: Generarl programming question. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-11 21:19 +0200
          Re: Generarl programming question. Terry Reedy <tjreedy@udel.edu> - 2015-04-11 17:12 -0400
            Re: Generarl programming question. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-12 00:05 +0200
              Re: Generarl programming question. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-12 15:04 +1000
  Re: Generarl programming question. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-12 01:25 +1000
    Re: Generarl programming question. jonas.thornvall@gmail.com - 2015-04-11 08:36 -0700

csiph-web