Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.04; 'instance,': 0.05; 'exceptions': 0.09; 'given,': 0.09; 'subject:Function': 0.09; 'def': 0.15; 'library': 0.15; 'chained': 0.16; 'debugger.': 0.16; 'exceptions.': 0.16; 'frame).': 0.16; 'nesting': 0.16; 'parks': 0.16; 'subject:Checking': 0.16; 'travis': 0.16; '\xa0for': 0.16; 'cc:addr:python-list': 0.16; 'written': 0.16; 'wrote:': 0.16; 'cc:no real name:2**0': 0.20; 'trying': 0.21; "doesn't": 0.22; 'cc:2**0': 0.22; 'header:In- Reply-To:1': 0.22; '(or': 0.23; 'delayed': 0.23; 'least,': 0.23; 'parameters.': 0.23; '\xa0if': 0.23; 'pm,': 0.24; 'aug': 0.24; 'stack': 0.24; 'do,': 0.25; 'guess': 0.26; 'function': 0.27; 'concern': 0.28; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'example': 0.30; 'sun,': 0.30; 'received:209.85.161.46': 0.31; 'received:mail- fx0-f46.google.com': 0.31; 'error': 0.32; 'cases': 0.32; 'this.': 0.32; 'source': 0.33; 'there': 0.33; 'algorithms': 0.34; 'received:209.85.161': 0.35; 'useful': 0.36; 'skip:" 10': 0.36; 'using': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'finding': 0.39; 'called': 0.40; 'agreed': 0.40; 'where': 0.40; 'true;': 0.67; 'deep,': 0.84; 'hand.': 0.84; 'false;': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=U9yjYPEmylKPJIe8zWUqz6gcGwnU4F2VG+tD7GszC+Y=; b=G75t0f6gdHJYPdcoJnJZrgNPKjWGhWuFuvoo0sGt/ouYJoHaBS4cQBV7/WBmx4/kH0 jU2+Tm/k1UeGQhJIGY3LhRY+9DnjHexOQIduLu+boirJO7AQjKWit9wsTSUaOyL8Mc8d WlmSYi6JTQnaRQES5qB9CUKbW/hzWeIlJHwdw= MIME-Version: 1.0 In-Reply-To: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> From: Ian Kelly Date: Sun, 28 Aug 2011 18:40:22 -0600 Subject: Re: Checking Signature of Function Parameter To: Travis Parks Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314578453 news.xs4all.nl 2412 [2001:888:2000:d::a6]:49166 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12365 On Sun, Aug 28, 2011 at 3:20 PM, Travis Parks wrot= e: > I am trying to write an algorithms library in Python. Most of the > functions will accept functions as parameters. For instance, there is > a function called any: > > def any(source, predicate): > =A0 =A0for item in source: > =A0 =A0 =A0 =A0if predicate(item): > =A0 =A0 =A0 =A0 =A0 =A0return true; > =A0 =A0return false; Perhaps not the best name, since there is already a built-in called "any" that would be masked by this. Using the built-in, "any(source, predicate)" would be written as "any(predicate(x) for x in source)" > I guess my concern is mostly with the delayed exceptions. It is hard > to find the source of an error when it doesn't happen immediately. I > am writing this library so all of the calls can be chained together > (composed). If this nesting gets really deep, finding the source is > hard to do, even with a good debugger. Agreed that there are cases where it is useful to do this. But there is no delayed execution in the example you've given, so the exceptions will happen immediately (or at least, within the same stack frame). The stack traces will still come from the "any" function and will look basically the same as the stack traces you'll get from raising the exceptions by hand. HTH, Ian