Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106602 > unrolled thread
| Started by | "Charles T. Smith" <cts.private.yahoo@gmail.com> |
|---|---|
| First post | 2016-04-06 20:21 +0000 |
| Last post | 2016-04-07 07:25 +0000 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
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
| From | "Charles T. Smith" <cts.private.yahoo@gmail.com> |
|---|---|
| Date | 2016-04-06 20:21 +0000 |
| Subject | recursive methods require implementing a stack? |
| Message-ID | <ne3r48$bk8$1@dont-email.me> |
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?
[toc] | [next] | [standalone]
| From | Rob Gaddi <rgaddi@highlandtechnology.invalid> |
|---|---|
| Date | 2016-04-06 20:28 +0000 |
| Message-ID | <ne3rhv$e1e$1@dont-email.me> |
| In reply to | #106602 |
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. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix.
[toc] | [prev] | [next] | [standalone]
| From | "Charles T. Smith" <cts.private.yahoo@gmail.com> |
|---|---|
| Date | 2016-04-07 06:46 +0000 |
| Message-ID | <ne4vo4$htk$1@dont-email.me> |
| In reply to | #106603 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Michael Selik <michael.selik@gmail.com> |
|---|---|
| Date | 2016-04-07 07:25 +0000 |
| Message-ID | <mailman.4.1460013967.2253.python-list@python.org> |
| In reply to | #106615 |
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. >
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web