Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95033
| References | (2 earlier) <bbcb163b-43a2-497a-8782-4228de0cb6e9@googlegroups.com> <01c7a472-9186-4e20-8b96-ae2c27af70f6@googlegroups.com> <mailman.1243.1438792146.3674.python-list@python.org> <85e343b4-2265-4e65-90ae-53d00ff88ebd@googlegroups.com> <ca61d6bf-fcfd-4e9c-acae-ff5c2f7fb2ee@googlegroups.com> |
|---|---|
| Date | 2015-08-06 03:10 +1000 |
| Subject | Re: Is this an example of tail recursion? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1244.1438794604.3674.python-list@python.org> (permalink) |
On Thu, Aug 6, 2015 at 2:51 AM, Rustom Mody <rustompmody@gmail.com> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is this an example of tail recursion? jennyfurtado2@gmail.com - 2015-08-05 08:13 -0700
Re: Is this an example of tail recursion? Rustom Mody <rustompmody@gmail.com> - 2015-08-05 08:21 -0700
Re: Is this an example of tail recursion? jennyfurtado2@gmail.com - 2015-08-05 08:37 -0700
Re: Is this an example of tail recursion? Chris Angelico <rosuav@gmail.com> - 2015-08-06 01:54 +1000
Re: Is this an example of tail recursion? Rustom Mody <rustompmody@gmail.com> - 2015-08-05 09:10 -0700
Re: Is this an example of tail recursion? jennyfurtado2@gmail.com - 2015-08-05 09:15 -0700
Re: Is this an example of tail recursion? Chris Angelico <rosuav@gmail.com> - 2015-08-06 02:28 +1000
Re: Is this an example of tail recursion? jennyfurtado2@gmail.com - 2015-08-05 09:41 -0700
Re: Is this an example of tail recursion? Rustom Mody <rustompmody@gmail.com> - 2015-08-05 09:51 -0700
Re: Is this an example of tail recursion? Chris Angelico <rosuav@gmail.com> - 2015-08-06 03:10 +1000
Re: Is this an example of tail recursion? Chris Angelico <rosuav@gmail.com> - 2015-08-06 01:51 +1000
Re: Is this an example of tail recursion? jenny <jennyfurtado2@gmail.com> - 2015-08-05 08:59 -0700
csiph-web