Path: csiph.com!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'pypy': 0.07; 'cc:addr :python-list': 0.09; '*is*': 0.09; 'python': 0.10; 'syntax': 0.13; 'explicitly': 0.15; 'thu,': 0.15; "*isn't*": 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'operator.': 0.16; 'sees': 0.16; 'subject:recursion': 0.16; 'wrote:': 0.16; 'integer': 0.18; 'all,': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'machine': 0.21; 'explicit': 0.22; 'am,': 0.23; 'code.': 0.23; 'implemented': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'define': 0.27; 'equivalent': 0.27; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'record': 0.29; 'cases.': 0.29; 'tail': 0.29; 'becomes': 0.30; 'call.': 0.30; "can't": 0.32; 'except': 0.34; 'running': 0.34; 'that,': 0.34; 'received:google.com': 0.35; 'cases': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'no,': 0.38; 'turned': 0.38; 'anything': 0.38; 'whatever': 0.39; 'does': 0.39; 'is.': 0.63; 'chrisa': 0.84; 'iow': 0.84; "there'll": 0.84; 'subject:this': 0.85; 'to:none': 0.91; 'ultimate': 0.93 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=WLZkc9YM+QcZTPFkqMsjDw9vnbGnwM1Uk7A4VAlOdJw=; b=Mkhq99qu8ZSe0NkjhvpnyWZDAIUWzu3iNjIVv3Jn3no62EcjLiRL+fsYGI+P8UQQaw gwciVSP4YapNnKa8uAkSqpVyjJEwmY1/3gAE0znvSCX9d67Ewc/actPaWvocTOqQ/lwh bapoeaRmFVsha3JUeOJyvwQF0R/SsxUn6ePTNQVp1b6T0Jy5sOYpc0HmSeM9YX0EysNV YTLmECz8APVnrtpqWHHR8sMPUxrzz6AgZokjRtJbZGbpHbIzcNp5QtYZ71w5YAzL0OZY A4+RVv9WFn3Z3hxHEKsIEKyBPNLuhI6hsXr5MEVfa78Y0k5lEIK2MdGM5aeG9FoRcwL7 vlDA== MIME-Version: 1.0 X-Received: by 10.107.31.134 with SMTP id f128mr10215409iof.19.1438792137514; Wed, 05 Aug 2015 09:28:57 -0700 (PDT) In-Reply-To: <01c7a472-9186-4e20-8b96-ae2c27af70f6@googlegroups.com> References: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> <01c7a472-9186-4e20-8b96-ae2c27af70f6@googlegroups.com> Date: Thu, 6 Aug 2015 02:28:57 +1000 Subject: Re: Is this an example of tail recursion? 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1438792146 news.xs4all.nl 2884 [2001:888:2000:d::a6]:46858 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95029 On Thu, Aug 6, 2015 at 2:10 AM, Rustom Mody wrote: > 1 + x > does not *call* 1 .__add__(x) > It *is* that > [Barring corner cases of radd etc] > IOW I am desugaring the syntax into explicit method-calls so you can see > all the calls explicitly > Then it becomes evident -- visibly and in fact --that the tail call is the > __add__ method not the solderdiersVsDefenders Except that it *isn't* that, precisely because of those other cases. When Python sees an expression like "1 + x" and doesn't yet know what x is, it can't do anything other than record the fact that there'll be a BINARY_ADD of the integer 1 and whatever that thing is. That object might well define __radd__, so the call is most definitely not equivalent to the operator. And the ultimate result of that addition might not even be a function call at all, if it's implemented in C. Or if you're running in PyPy and the optimizer turned it into machine code. So no, even though you can define addition for *your own classes* using __add__ or __radd__, you can't reinterpret every addition as a function call. ChrisA