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


Groups > comp.lang.python > #88825

Re: Generarl programming question.

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 <rosuav@gmail.com>
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 <dcb7fd6b-3a96-47e8-91f6-49b21f7bf605@googlegroups.com> <mailman.222.1428765309.12925.python-list@python.org> <1f4ab217-ed8e-4d8c-ba61-907465a4839a@googlegroups.com>
Date Sun, 12 Apr 2015 01:28:28 +1000
Subject Re: Generarl programming question.
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.223.1428766115.12925.python-list@python.org> (permalink)
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

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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