Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '*not*': 0.07; 'implements': 0.07; 'cc:addr:python-list': 0.09; 'likewise': 0.09; 'similar,': 0.09; 'underlying': 0.09; 'python': 0.10; 'python.': 0.11; 'stack': 0.13; 'def': 0.13; 'applies': 0.15; 'thu,': 0.15; 'ctypes.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'libc': 0.16; 'operation.': 0.16; 'printf': 0.16; 'subject:recursion': 0.16; 'wrote:': 0.16; 'pointer': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'extension': 0.20; 'ctypes': 0.22; 'am,': 0.23; 'defined': 0.23; 'seems': 0.23; 'import': 0.24; 'implemented': 0.24; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; 'module': 0.25; 'chris': 0.26; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'idea': 0.28; 'looks': 0.29; 'about.': 0.29; 'behaving': 0.29; 'callable': 0.29; 'declared': 0.29; 'really,': 0.29; 'sure,': 0.29; 'objects': 0.29; 'call.': 0.30; 'certainly': 0.30; 'point': 0.33; 'call,': 0.33; 'that,': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'replace': 0.35; "isn't": 0.35; 'but': 0.36; 'cases': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'method': 0.37; 'anything': 0.38; 'well.': 0.40; 'where': 0.40; 'within': 0.64; 'dont': 0.64; 'here': 0.66; 'talking': 0.67; 'action.': 0.84; 'beside': 0.84; 'chrisa': 0.84; 'subject:this': 0.85; 'to:none': 0.91 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=Zpk4EPNxAtbJ3/Hs5nyJv4cagofAa816mbvTXdtoJWw=; b=FlFIHn4jY5yYqIWC6XrHAhDzAakOhruSpVOWDmnqjp1G0mYDVMHaIfaHHSkBZH5UcK tiwvmoALe1KDGLlWOdVfzKPwMQNcIC+B7+h47E4VefR0KcZVZ+OaEzuowDzfZxrOTpG7 M/fQyPmwq7CmDkELFddkdtE3GROlzSNa1lAGYw1JIrTfXtRFqUsL7A68lQVCiehgAm2D vYFqTiAkNcjxdlmcbeZCOE86fSb4OQlntPIz/OYBdR1uwgycoZ4GgJx/8WPhBz9iI95u l0+U2WBA2eCYTdKRJ8otyq28W21cj48KnGQVjaBX4braNKu3EHNgpp5WPZjvzglghAsB McFA== MIME-Version: 1.0 X-Received: by 10.107.31.134 with SMTP id f128mr10409480iof.19.1438794600383; Wed, 05 Aug 2015 10:10:00 -0700 (PDT) In-Reply-To: References: <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> <01c7a472-9186-4e20-8b96-ae2c27af70f6@googlegroups.com> <85e343b4-2265-4e65-90ae-53d00ff88ebd@googlegroups.com> Date: Thu, 6 Aug 2015 03:10:00 +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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1438794604 news.xs4all.nl 2953 [2001:888:2000:d::a6]:37640 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95033 On Thu, Aug 6, 2015 at 2:51 AM, Rustom Mody wrote: > And I continue to have no idea what Chris is talking about. > Here is C printf >>>> from ctypes import * >>>> cdll.LoadLibrary("libc.so.6") >>>> libc = CDLL("libc.so.6") >>>> libc.printf(b"%s", b"Hello") > 5 > Hello>>> > > As far as I can see printf is a C function and its behaving like (an > ill-behaved) python function as well. > Likewise for anything else written ina C extension module > Or a C-builtin > > If its callable from within python its python > That it may also be C seems to me beside the point > [As I said I dont get the point] Sure, if it's callable from within Python. Where is this implemented in CPython? def f(x): return x+2 f(1) There's PyNumber_Add() in abstract.c, which looks for the nb_add slot. That contains a pointer to long_add, which is defined in longobject.c. Is that the same thing as (1).__add__? Not really, but that's kinda what implements the underlying operation. Also, the function is declared as 'static', so I don't think you can find it using ctypes. Adding two Python objects is *not* a function call. It is an operator-controlled action. It's very similar, in many ways, to a method call, but it isn't exactly that, and it certainly isn't the sort of thing that you could tail-call-optimize as the concept applies only to cases where you can actually replace a stack frame. ChrisA