Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #88825
| References | <dcb7fd6b-3a96-47e8-91f6-49b21f7bf605@googlegroups.com> <mailman.222.1428765309.12925.python-list@python.org> <1f4ab217-ed8e-4d8c-ba61-907465a4839a@googlegroups.com> |
|---|---|
| Date | 2015-04-12 01:28 +1000 |
| Subject | Re: Generarl programming question. |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.223.1428766115.12925.python-list@python.org> (permalink) |
On Sun, Apr 12, 2015 at 1:22 AM, <jonas.thornvall@gmail.com> wrote:
> Thanks i was worried, i try to make a generic base choice algorithm that should work for anybase, and i just realised that the bignumb add would need to call the bignumb subtraction and viceversa. I thought there may be instances but i was not sure.
>
> But I have a feeling the code will be hard to debug.
The thing to watch out for is unbounded recursion, where they might
call each other forever. But you could easily define your two
functions to fall back to the other like this:
def add(x, y):
if is_negative(y): return subtract(x, -y)
# implement addition with known-positive y
def subtract(x, y):
if is_negative(y): return add(x, -y)
# implement subtraction with known-positive y
There's no problem here, and no possible conflict. (I don't know how
it'd actually help, implementing it like this, but it's certainly
legal.)
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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