Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95029
| References | <53903f1c-a740-4508-9d24-0b0bec9ad339@googlegroups.com> <eb5d250a-aa9a-4cf1-9123-ab64a2188538@googlegroups.com> <bbcb163b-43a2-497a-8782-4228de0cb6e9@googlegroups.com> <01c7a472-9186-4e20-8b96-ae2c27af70f6@googlegroups.com> |
|---|---|
| Date | 2015-08-06 02:28 +1000 |
| Subject | Re: Is this an example of tail recursion? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1243.1438792146.3674.python-list@python.org> (permalink) |
On Thu, Aug 6, 2015 at 2:10 AM, Rustom Mody <rustompmody@gmail.com> 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
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