Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.041 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'algorithm': 0.04; 'cc:addr :python-list': 0.11; 'def': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:programming': 0.16; 'subject:question.': 0.16; 'subtraction': 0.16; 'sure.': 0.16; 'y):': 0.16; 'wrote:': 0.18; 'implementing': 0.19; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'cc:2**0': 0.24; 'define': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'could': 0.34; 'problem': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'instances': 0.36; 'thanks': 0.36; 'possible': 0.36; 'should': 0.36; 'two': 0.37; 'easily': 0.37; 'implement': 0.38; 'generic': 0.38; '12,': 0.39; 'help,': 0.39; 'how': 0.40; 'back': 0.62; 'feeling': 0.68; '2015': 0.84; "it'd": 0.84; 'recursion,': 0.84; 'forever.': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=m8dfUnJT7jyLzZoSCB2FqkVCUXX3zOa/wC/ybgOcocY=; b=ZkktfjRyD1hiBlbPEXm9CID+iUYv2/2m9/lSr+CN/VRh4iJmr/5PFZIru4ppPxStGx RJVQcb0cH7Onqxp+62BGBmaeABGGg/OKUWM+324FpFsKkwWS4vdJU19ZMWNpGAfNlcIl /K07T3tipKLsn3voYpM/qcI50IlQE2GE/khvXE4NKpBrHQBW4AwBjW7VFVNBdJfTetpO qbkFoMMaKb9wEWUzExYVoGgfPvKE+EjHBaOyaBzG1aYdhUPznQQlFuaCHo5nXCgw1wKh 8wdqd6+34tOZAjUQRmq16TjIRznL0oFeoo63Q4MtNs+XeDsAICd0CVVbDlRu1NyGQ7zw eWJg== MIME-Version: 1.0 X-Received: by 10.107.134.206 with SMTP id q75mr9783560ioi.27.1428766108278; Sat, 11 Apr 2015 08:28:28 -0700 (PDT) In-Reply-To: <1f4ab217-ed8e-4d8c-ba61-907465a4839a@googlegroups.com> References: <1f4ab217-ed8e-4d8c-ba61-907465a4839a@googlegroups.com> Date: Sun, 12 Apr 2015 01:28:28 +1000 Subject: Re: Generarl programming question. From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1428766115 news.xs4all.nl 2907 [2001:888:2000:d::a6]:39726 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:88825 On Sun, Apr 12, 2015 at 1:22 AM, 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