Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Veek M
Marko Rauhamaa wrote: > Veek M : > >> https://en.wikipedia.org/wiki/Call_stack >> >> 'Programming languages that support nested subroutines also have a >> field in the call frame that points to the stack frame of the latest >> activation of the procedure that most closely encapsulates the >> call

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Antoon Pardon
Op 13-12-16 om 08:13 schreef Veek M: > 4. When you call a nested function (decorator), it generally returns a > wrapper function but I thought he was just returning a reference to a > function object but obviously since it can see it's environment, how is > the stack being setup? Here you are n

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Veek M
http://web.archive.org/web/20111030134120/http://www.sidhe.org/~dan/blog/archives/000211.html (great tail recursion article - best i've seen! SO doesn't really explain it unless you already knew it to begin with, but here's the link:http://stackoverflow.com/questions/310974/what-is-tail-call-opti

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Marko Rauhamaa
Veek M : > https://en.wikipedia.org/wiki/Call_stack > > 'Programming languages that support nested subroutines also have a field > in the call frame that points to the stack frame of the latest > activation of the procedure that most closely encapsulates the callee, > i.e. the immediate scope o

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Veek M
Veek M wrote: > I was reading the wiki on 'Call stack' because I wanted to understand > what a traceback object was. My C/C++ isn't good enough to deal with > raw python source since I have no background in CS. Also, you just > can't dive into the python src - it takes a good deal of reading and >

Re: nested functions

2006-06-15 Thread Kent Johnson
Fredrik Lundh wrote: > George Sakkis wrote: > >> It shouldn't come as a surprise if it turns out to be slower, since the >> nested function is redefined every time the outer is called. > > except that it isn't, really: all that happens is that a new function object > is created from > prebuilt p

Re: nested functions

2006-06-15 Thread Gregory Petrosyan
Thanks everybody for your help! -- http://mail.python.org/mailman/listinfo/python-list

Re: nested functions

2006-06-15 Thread George Sakkis
Duncan Booth wrote: > Fredrik Lundh wrote: > > > George Sakkis wrote: > > > >> It shouldn't come as a surprise if it turns out to be slower, since > >> the nested function is redefined every time the outer is called. > > > > except that it isn't, really: all that happens is that a new function > >

Re: nested functions

2006-06-15 Thread Duncan Booth
Fredrik Lundh wrote: > George Sakkis wrote: > >> It shouldn't come as a surprise if it turns out to be slower, since >> the nested function is redefined every time the outer is called. > > except that it isn't, really: all that happens is that a new function > object is created from prebuilt par

Re: nested functions

2006-06-15 Thread Fredrik Lundh
George Sakkis wrote: > It shouldn't come as a surprise if it turns out to be slower, since the > nested function is redefined every time the outer is called. except that it isn't, really: all that happens is that a new function object is created from prebuilt parts, and assigned to a local varia

Re: nested functions

2006-06-15 Thread Duncan Booth
Georg Brandl wrote: > That's right. However, if the outer function is only called a few times > and the nested function is called a lot, the locals lookup for the > function name is theoretically faster than the globals lookup. Also, > in methods you can use closures, so you don't have to pass, fo

Re: nested functions

2006-06-14 Thread Georg Brandl
George Sakkis wrote: > Ben Finney wrote: > >> "Gregory Petrosyan" <[EMAIL PROTECTED]> writes: >> >> > I often make helper functions nested, like this: >> > >> > def f(): >> > def helper(): >> > ... >> > ... >> > >> > is it a good practice or not? >> >> You have my blessing. Used we

Re: nested functions

2006-06-14 Thread George Sakkis
Ben Finney wrote: > "Gregory Petrosyan" <[EMAIL PROTECTED]> writes: > > > I often make helper functions nested, like this: > > > > def f(): > > def helper(): > > ... > > ... > > > > is it a good practice or not? > > You have my blessing. Used well, it makes for more readable code.

Re: nested functions

2006-06-14 Thread Ben Finney
"Gregory Petrosyan" <[EMAIL PROTECTED]> writes: > I often make helper functions nested, like this: > > def f(): > def helper(): > ... > ... > > is it a good practice or not? You have my blessing. Used well, it makes for more readable code. > What about performance of such const

Re: nested functions

2006-04-15 Thread Fredrik Lundh
Lawrence D'Oliveiro wrote: > >BUT 'b' and 'c' simply do not exist outside the 'a' world. > > It's worth distinguishing between the _names_ 'b' and 'c' and the > _functions_ referred to by those names. The _names_ certainly do not > exist outside of the scope of the function referred to by 'a' (any

Re: nested functions

2006-04-14 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>, "Thomas Bartkus" <[EMAIL PROTECTED]> wrote: >Your function 'a' is it's own little world where functions 'b' and 'c' >exist. >Your code inside 'a' can call 'b' or 'c' - neat as you please. > >BUT 'b' and 'c' simply do not exist outside the 'a' world. It's worth dis

Re: nested functions

2006-04-14 Thread bruno at modulix
Szabolcs Berecz wrote: > On 14 Apr 2006 04:37:54 -0700, [EMAIL PROTECTED] > <[EMAIL PROTECTED]> wrote: > >>def a(): >> def b(): >>print "b" >> def c(): >>print "c" >> >>how can i call c() ?? > > > Function c() is not meant to be called from outside function a(). > That's what a nested

Re: nested functions

2006-04-14 Thread Fredrik Lundh
Thomas Bartkus wrote: > I, for one, am so glad to have nested functions again ;-) again ? Python has always supported nested functions. it's the scoping rules that have changed; before the change from LGB to LEGB, you had to explictly import objects from outer scopes. -- http://mail.pytho

Re: nested functions

2006-04-14 Thread Thomas Bartkus
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > hi > just curious , if i have a code like this? > > def a(): > def b(): > print "b" > def c(): > print "c" > > how can i call c() ?? Your function 'a' is it's own little world where functions 'b' and 'c' exist. Your code ins

Re: nested functions

2006-04-14 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > just curious , if i have a code like this? > > def a(): > def b(): > print "b" > def c(): > print "c" > > how can i call c() ?? in the same way as you'd access the variable "c" in this example: def a(): c = 10 (that is, by calling the function

Re: nested functions

2006-04-14 Thread Szabolcs Berecz
On 14 Apr 2006 04:37:54 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > def a(): > def b(): > print "b" > def c(): > print "c" > > how can i call c() ?? Function c() is not meant to be called from outside function a(). That's what a nested function is for: localizing it's usage a

Re: nested functions

2006-04-14 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > hi > just curious , if i have a code like this? > > def a(): > def b(): > print "b" > def c(): > print "c" > > how can i call c() ?? c is a name in the local scope of a(). You can call c from within a, where the name is in scope, or you can return c or in