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


Groups > comp.lang.python > #106620

Re: recursive methods require implementing a stack?

From Michael Selik <michael.selik@gmail.com>
Newsgroups comp.lang.python
Subject Re: recursive methods require implementing a stack?
Date 2016-04-07 07:25 +0000
Message-ID <mailman.4.1460013967.2253.python-list@python.org> (permalink)
References <ne3r48$bk8$1@dont-email.me> <ne3rhv$e1e$1@dont-email.me> <ne4vo4$htk$1@dont-email.me> <CAGgTfkOHXCsyRsa2ea5difNVJQ6uQxULw2HE36aw6Sac3Yx6MQ@mail.gmail.com>

Show all headers | View raw


On Thu, Apr 7, 2016, 7:51 AM Charles T. Smith <cts.private.yahoo@gmail.com>
wrote:

> On Wed, 06 Apr 2016 20:28:47 +0000, Rob Gaddi wrote:
>
> > Charles T. Smith wrote:
> >
> >> I just tried to write a recursive method in python - am I right that
> local
> >> variables are only lexically local scoped, so sub-instances have the
> same
> >> ones?  Is there a way out of that?  Do I have to push and pop my own
> simulated
> >> stack frame entry?
> >
> > You have been badly misled.  Python local variables are frame local, and
> > recursion just works.
>
>
> Well, I probably stumbled astray due to my own stupidity, can't blame
> anybody
> of having misled me...  ;)
>
> So it's a bug in my program!  Good news!  Thank you.
>

I'm guessing you are passing a list or dict to the recursive call and
discovering that the object is passed rather than a copy. Note that this is
not pass-by-reference, but "pass by object", for your Googling.

>

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


Thread

recursive methods require implementing a stack? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-04-06 20:21 +0000
  Re: recursive methods require implementing a stack? Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-04-06 20:28 +0000
    Re: recursive methods require implementing a stack? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-04-07 06:46 +0000
      Re: recursive methods require implementing a stack? Michael Selik <michael.selik@gmail.com> - 2016-04-07 07:25 +0000

csiph-web