Re: getting rid of the recursion in __getattribute__

2023-05-25 Thread Peter Otten
On 24/05/2023 15:37, A KR wrote: It is perfectly explained in the standards here [1] saying that: In order to avoid infinite recursion in this method, its implementation should always call the base class method with the same name to access any attributes it needs, for example, object

getting rid of the recursion in __getattribute__

2023-05-24 Thread A KR
It is perfectly explained in the standards here [1] saying that: In order to avoid infinite recursion in this method, its implementation should always call the base class method with the same name to access any attributes it needs, for example, object.__getattribute__(self, name). Therefore

Re: Fwd: timedelta object recursion bug

2022-07-28 Thread Dieter Maurer
Please stay on the list (such that others can help, too) Ben Hirsig wrote at 2022-7-29 06:53 +1000: >Thanks for the replies, I'm just trying to understand why this would be >useful? > >E.g. why does max need a min/max/resolution, and why would these attributes >themselves need a min/max/resolution

Re: Fwd: timedelta object recursion bug

2022-07-28 Thread Dieter Maurer
les-of-usage-timedelta > > > >It appears as though the timedelta object recursively adds its own >attributes (min, max, resolution) as further timedelta objects. I’m not >sure how deep they go, but presumably hitting the recursion limit. If you look at the source, you will see that

Re: Fwd: timedelta object recursion bug

2022-07-28 Thread Jon Ribbens via Python-list
ge-timedelta > > It appears as though the timedelta object recursively adds its own > attributes (min, max, resolution) as further timedelta objects. I’m not > sure how deep they go, but presumably hitting the recursion limit. > >>from datetime import timedelta >>year

Re: Fwd: timedelta object recursion bug

2022-07-28 Thread MRAB
It appears as though the timedelta object recursively adds its own attributes (min, max, resolution) as further timedelta objects. I’m not sure how deep they go, but presumably hitting the recursion limit. from datetime import timedelta year = timedelta(days=365) print(year.max

Fwd: timedelta object recursion bug

2022-07-28 Thread Ben Hirsig
object recursively adds its own attributes (min, max, resolution) as further timedelta objects. I’m not sure how deep they go, but presumably hitting the recursion limit. >from datetime import timedelta >year = timedelta(days=365) >print(year.max) 9 days, 23:59:59.9

Re: why this code giving recursion error????

2022-06-26 Thread dn
On 26/06/2022 23.00, נתי שטרן wrote: > I FIXED THE CODE  For the benefit of future-readers: how did you go about fixing it? What was wrong? -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list

Re: why this code giving recursion error????

2022-06-26 Thread נתי שטרן
k > > > > return sre_compile.compile( > > pattern, flags | p.state.flags, code, > > p.state.groups-1, > > groupindex, tuple(indexgroup) > > ) > > > Why would any code give a recursion error? > > With recursion problem

Re: why this code giving recursion error????

2022-06-26 Thread נתי שטרן
and i ask also what's the problem with this function: def _code(p, flags): flags = p.state.flags | flags code = [] # compile info block sre_compile._compile_info(code, p, flags) # compile the pattern sre_compile._compile(code, p.data, flags)

Re: why this code giving recursion error????

2022-06-26 Thread dn
for k, i in groupindex.items(): > indexgroup[i] = k > > return sre_compile.compile( > pattern, flags | p.state.flags, code, > p.state.groups-1, > groupindex, tuple(indexgroup) > ) Why would any code give a recu

Re: why this code giving recursion error????

2022-06-26 Thread נתי שטרן
stack trace: File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 5387, in class bottle: File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 5694, in bottle class Router(object): File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 5736, in Router rule_syntax = re.compil

why this code giving recursion error????

2022-06-26 Thread נתי שטרן
def compile(p, flags=0): # internal: convert pattern list to internal format if (isinstance(p,str)): pattern = p p = sre_parse.parse(p, flags) else: pattern = None code = _code(p, flags) if flags & SRE_FLAG_DEBUG:

Re: Recursion on list

2021-11-04 Thread Peter Pearson
On Thu, 4 Nov 2021 08:57:14 +0100, ast wrote: > > li = [] > > li.append(li) > > li > [[...]] > > >li[0][0][0][0] > [[...]] > > That's funny After the coming AI upheaval, such cruelty to machines will be considered punishable and not funny. -- To email me, substitute nowhere->runbox, invalid->c

Recursion on list

2021-11-04 Thread ast
> li = [] > li.append(li) > li [[...]] >li[0][0][0][0] [[...]] That's funny -- https://mail.python.org/mailman/listinfo/python-list

Re: Recursion on list

2021-11-04 Thread Pieter van Oostrum
ast writes: >> li = [] >> li.append(li) >> li > [[...]] > >>li[0][0][0][0] > [[...]] > > That's funny > You made a list whose only element is itself. In [1]: li = [] In [3]: li.append(li) In [4]: li[0] is li Out[4]: True -- Pieter van Oostrum www: http://pieter.vanoostrum.org/ PGP key: [8D

Algorithm of ordering in Python using recursion

2017-09-13 Thread Leo
b = [bmax,bmin]; For conceptual clarity we present the algorithm in recursion fashion. Wecomment on the truncation. The TBiSort recursion goes downward first portioning the initial data list a all the way to the base level (sublist length 1), then goes upward with monotonic merges. In TBiMerg

Re: zeep, infinite recursion

2017-05-31 Thread Steve D'Aprano
On Tue, 30 May 2017 05:58 pm, Nagy Lc3a1szlc3b3 Zsolt wrote: >> It was easier than I thought. It seems that zeep has a problem >> processing a basic WS-Security STS (Security Token Service, plain >> username+password authentication) document. I have changed the endpoint >> URL to example.com. Tota

Re: zeep, infinite recursion

2017-05-31 Thread Peter Otten
Nagy László Zsolt wrote: > > >> It was easier than I thought. It seems that zeep has a problem >> processing a basic WS-Security STS (Security Token Service, plain >> username+password authentication) document. I have changed the endpoint >> URL to example.com. Total size 11K compressed. I hope

Re: zeep, infinite recursion

2017-05-30 Thread Nagy László Zsolt
> It was easier than I thought. It seems that zeep has a problem > processing a basic WS-Security STS (Security Token Service, plain > username+password authentication) document. I have changed the endpoint > URL to example.com. Total size 11K compressed. I hope it is okay to > attach here. It wa

Re: zeep, infinite recursion

2017-05-30 Thread Nagy László Zsolt
> There are less than 100 elements defined in the WSDL, so it cannot be > the problem. It might be a recursive data definition, but then it should > be handled by zeep instead of entering into an intinite recursion. > > Well, I'll be working on an MWE and post it here later.

Re: zeep, infinite recursion

2017-05-30 Thread Nagy László Zsolt
>> line 259, in signature >> from zeep.xsd import ComplexType >> RecursionError: maximum recursion depth exceeded >> >> Looks like an infinite recursion to me. Due to a non-disclosure >> agreement, I'm not able to send you the example wsdl. > S

Re: zeep, infinite recursion

2017-05-29 Thread Peter Otten
Nagy László Zsolt wrote: > Running this command: > > python3.6 -m zeep exmaple.wsdl This example is no more, we heave ceased to see it, it's gone to meet its maker... this is an ex-ex-ample. > line 259, in signature > from zeep.xsd import ComplexType > RecursionE

Re: zeep, infinite recursion

2017-05-29 Thread Jussi Piitulainen
Nagy László Zsolt writes: > Running this command: > > python3.6 -m zeep exmaple.wsdl > > I get this (this is only the end of the traceback): > ... > from zeep.xsd import ComplexType > RecursionError: maximum recursion depth exceeded > > Looks like an infinite

zeep, infinite recursion

2017-05-29 Thread Nagy László Zsolt
ocal/lib/python3.6/dist-packages/zeep/xsd/elements/indicators.py", line 561, in signature parts.append('{%s: %s}' % (name, element.signature(schema, standalone=False))) File "/usr/local/lib/python3.6/dist-packages/zeep/xsd/elements/element.py", line 259, in signature from z

Re: I am comfused about the name behavior of Python in recursion

2016-10-06 Thread alister
On Wed, 05 Oct 2016 17:30:22 -0700, 380162267qq wrote: > Google told me Python name is a label attaching to the object. > But in this recursive function,the name 'a' will point to different > number object. > > def rec(a): > a+=1 if a<10: > rec(a) > print(a) > > rec(0)

Re: I am comfused about the name behavior of Python in recursion

2016-10-05 Thread Gregory Ewing
38016226...@gmail.com wrote: def rec(a): a+=1 if a<10: rec(a) print(a) rec(0) gives me 101 normally.Why it works? Because of the stack memory management? Yes. There isn't just one 'a' here, there's a different one each time rec is called. Thank yo

Re: I am comfused about the name behavior of Python in recursion

2016-10-05 Thread Ben Finney
38016226...@gmail.com writes: > Google told me Python name is a label attaching to the object. Well, “Google told me” has no necessary bearing on whether it's true :-) so that's not a good citation to give. If you need to know what Python terminology means, the Python documentation is better.

I am comfused about the name behavior of Python in recursion

2016-10-05 Thread 380162267qq
Google told me Python name is a label attaching to the object. But in this recursive function,the name 'a' will point to different number object. def rec(a): a+=1 if a<10: rec(a) print(a) rec(0) gives me 101 normally.Why it works? Because of the stack

Version 1.1 of the tco module (tail-calls, recursion, call/cc)

2015-11-06 Thread Th. Baruchel
The version 1.1 of the tco module is released. It is much more owerful since it now allows nested systems of continuations. The most important is probably rather that I took the time to write a very detailed presentation of the module on my blog: http://baruchel.github.io/ Regards, tb. -- https:/

Re: Is this an example of tail recursion?

2015-08-05 Thread Chris Angelico
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 pr

Re: Is this an example of tail recursion?

2015-08-05 Thread Rustom Mody
On Wednesday, August 5, 2015 at 10:11:30 PM UTC+5:30, wrote: > On Wednesday, August 5, 2015 at 10:29:21 AM UTC-6, Chris Angelico wrote: > > 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

Re: Is this an example of tail recursion?

2015-08-05 Thread jennyfurtado2
On Wednesday, August 5, 2015 at 10:29:21 AM UTC-6, Chris Angelico wrote: > 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

Re: Is this an example of tail recursion?

2015-08-05 Thread Chris Angelico
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 --th

Re: Is this an example of tail recursion?

2015-08-05 Thread jennyfurtado2
1 PM UTC+5:30, jennyf...@gmail.com > > > wrote: > > > > I am trying to learn differences between tail recursion and non tail > > > > recursion. > > > > > > > > Is the following recursive code tail recursive? > > > > If it is not how

Re: Is this an example of tail recursion?

2015-08-05 Thread Rustom Mody
differences between tail recursion and non tail > > > recursion. > > > > > > Is the following recursive code tail recursive? > > > If it is not how to convert it to tail recursion? > > > If it is how to convert it to non tail recursion? > > >

Re: Is this an example of tail recursion?

2015-08-05 Thread jenny
On Wednesday, August 5, 2015 at 9:52:14 AM UTC-6, Chris Angelico wrote: > On Thu, Aug 6, 2015 at 1:13 AM, wrote: > > I am trying to learn differences between tail recursion and non tail > > recursion. > > Tail recursion is where you do exactly this: > &g

Re: Is this an example of tail recursion?

2015-08-05 Thread Chris Angelico
dition function is pretty pointless. I mean, sure, it's technically a sort of tail call, but it's definitely not tail recursion, and it's such a trivial operation (adding one to a probably-small number) that it's hardly even worth mentioning. The main point of tail recursion is

Re: Is this an example of tail recursion?

2015-08-05 Thread Chris Angelico
On Thu, Aug 6, 2015 at 1:13 AM, wrote: > I am trying to learn differences between tail recursion and non tail > recursion. Tail recursion is where you do exactly this: return some_function(...) Absolutely nothing is allowed to happen around or after that function, and that also mea

Re: Is this an example of tail recursion?

2015-08-05 Thread jennyfurtado2
On Wednesday, August 5, 2015 at 9:21:33 AM UTC-6, Rustom Mody wrote: > On Wednesday, August 5, 2015 at 8:43:31 PM UTC+5:30, jennyf...@gmail.com > wrote: > > I am trying to learn differences between tail recursion and non tail > > recursion. > > > > Is the following

Re: Is this an example of tail recursion?

2015-08-05 Thread Rustom Mody
On Wednesday, August 5, 2015 at 8:43:31 PM UTC+5:30, jennyf...@gmail.com wrote: > I am trying to learn differences between tail recursion and non tail > recursion. > > Is the following recursive code tail recursive? > If it is not how to convert it to tail recursion? > If it is

Is this an example of tail recursion?

2015-08-05 Thread jennyfurtado2
I am trying to learn differences between tail recursion and non tail recursion. Is the following recursive code tail recursive? If it is not how to convert it to tail recursion? If it is how to convert it to non tail recursion? class CastleDefenseI: INFINITY = 9 def __init__(self

Re: Another tail recursion example

2015-07-28 Thread Terry Reedy
On 7/28/2015 5:28 PM, Paul Rubin wrote: Chris Angelico was asking for examples of tail recursion that didn't have obvious looping equivalents. Since there is a mechanical procedure for producing the equivalent *under the assumption that the function name will not be rebound*,

Re: Another tail recursion example

2015-07-28 Thread Ian Kelly
On Jul 28, 2015 1:36 PM, "Paul Rubin" wrote: > > Paul Rubin writes: > > Chris Angelico was asking for examples of tail recursion that didn't > > have obvious looping equivalents. Here's an Euler problem solution > > using memoization and (e

Re: Another tail recursion example

2015-07-28 Thread Paul Rubin
Paul Rubin writes: > Chris Angelico was asking for examples of tail recursion that didn't > have obvious looping equivalents. Here's an Euler problem solution > using memoization and (except that Python doesn't implement it) tail > recursion with an accumulator. Actu

Another tail recursion example

2015-07-28 Thread Paul Rubin
Chris Angelico was asking for examples of tail recursion that didn't have obvious looping equivalents. Here's an Euler problem solution using memoization and (except that Python doesn't implement it) tail recursion with an accumulator. # Solution to Euler problem 14, us

Re: My attempts in playing with tail-recursion in python

2015-05-17 Thread Fred Spiessens
Hi Thomas, I like what you've been doing. I think it would also be great if the "leave the loop" detector would be the actual stop condition in the recursion, applied to the arguments of the call. That would of course force you to split the recursive function in two functions: on

Re: Tail recursion to while iteration in 2 easy steps

2013-10-09 Thread Charles Hixson
On 10/08/2013 02:22 AM, Steven D'Aprano wrote: On Mon, 07 Oct 2013 20:27:13 -0700, Mark Janssen wrote: But even putting that aside, even if somebody wrote such a description, it would be reductionism gone mad. What possible light on the problem would be shined by a long, long list of machine co

Re: Tail recursion to while iteration in 2 easy steps

2013-10-08 Thread Jussi Piitulainen
Alain Ketterlin writes: > Antoon Pardon writes: > > > Op 07-10-13 19:15, Alain Ketterlin schreef: > > [...] > >> That's fine. My point was: you can't at the same time have full > >> dynamicity *and* procedural optimizations (like tail call opt). > >> Everybody should be clear about the trade-off.

Re: Tail recursion to while iteration in 2 easy steps

2013-10-08 Thread Antoon Pardon
o have serious short comings that couldn't be remedied easily? > > The entire point of tail call optimization requires not keeping the > intervening stack frames around, in _any_ form, so as to allow > arbitrarily deep recursion without ever having the possibility of a > stac

Re: Tail recursion to while iteration in 2 easy steps

2013-10-08 Thread Steven D'Aprano
On Mon, 07 Oct 2013 20:27:13 -0700, Mark Janssen wrote: But even putting that aside, even if somebody wrote such a description, it would be reductionism gone mad. What possible light on the problem would be shined by a long, long list of machine code operations, even if written

Re: Tail recursion to while iteration in 2 easy steps

2013-10-08 Thread Antoon Pardon
Op 08-10-13 01:50, Steven D'Aprano schreef: > On Mon, 07 Oct 2013 15:47:26 -0700, Mark Janssen wrote: > >> I challenge you to get >> down to the machine code in scheme and formally describe how it's doing >> both. > > For which machine? > > Or are you assuming that there's only one machine code

Re: Tail recursion to while iteration in 2 easy steps

2013-10-08 Thread Alain Ketterlin
Antoon Pardon writes: > Op 07-10-13 19:15, Alain Ketterlin schreef: [...] >> That's fine. My point was: you can't at the same time have full >> dynamicity *and* procedural optimizations (like tail call opt). >> Everybody should be clear about the trade-off. > > Your wrong. Full dynamics is not i

Re: Tail recursion to while iteration in 2 easy steps

2013-10-08 Thread Alain Ketterlin
the arguments and jump to the top of this > function". Some people have introduced the idea of _further_ > optimizations, transforming "near" tail recursion (i.e. return self()+1) > into tail recursion, and _that_ depends on knowing the identity of the > function (though a

Re: Tail recursion to while iteration in 2 easy steps

2013-10-08 Thread Jussi Piitulainen
Steven D'Aprano writes: > Far more useful would be a high-level description of Scheme's > programming model. If names can be rebound on the fly, how does > Scheme even tell whether something is a recursive call or not? > > def foo(arg): > do stuff here > foo(arg-1) # how does Scheme know

Re: Tail recursion to while iteration in 2 easy steps

2013-10-08 Thread Jussi Piitulainen
random...@fastmail.us writes: > The entire point of tail call optimization requires not keeping the > intervening stack frames around, in _any_ form, so as to allow > arbitrarily deep recursion without ever having the possibility of a > stack overflow. An implementation which reduced

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Mark Janssen
>> Yeah, and this is where two models of computation have been conflated, >> creating magical effects, confusing everybody. I challenge you to get >> down to the machine code in scheme and formally describe how it's >> doing both. > > Which two models of computation are you talking about? And what

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Mark Janssen
>>> But even putting that aside, even if somebody wrote such a description, >>> it would be reductionism gone mad. What possible light on the problem >>> would be shined by a long, long list of machine code operations, even >>> if written using assembly mnemonics? >> >> Only that you've got a consi

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Piet van Oostrum
ll optimization there is no need to do tail recursion optimization. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] -- https://mail.python.org/mailman/listinfo/python-list

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Piet van Oostrum
Mark Janssen writes: > Yeah, and this is where two models of computation have been conflated, > creating magical effects, confusing everybody. I challenge you to get > down to the machine code in scheme and formally describe how it's > doing both. Which two models of computation are you talking

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Steven D'Aprano
On Mon, 07 Oct 2013 17:16:35 -0700, Mark Janssen wrote: > It's like this: there *should* be one-to-one mappings between the > various high-level constructs to the machine code, varying only between > different chips (that is the purpose of the compiler after all), yet for > some operations, in lan

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Mark Janssen
On Mon, Oct 7, 2013 at 4:50 PM, Steven D'Aprano wrote: > On Mon, 07 Oct 2013 15:47:26 -0700, Mark Janssen wrote: >> I challenge you to get >> down to the machine code in scheme and formally describe how it's doing >> both. > > For which machine? Right, I should stop assuming a modern implementati

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Mark Janssen
> Only that you've got a consistent, stable (and therefore, > formalizable) translation from your language to the machine. That's > all. Everything else is magic. Do you know that the Warren > Abstraction Engine used to power the predicate logic in Prolog into > machien code for a VonNeumann mac

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Steven D'Aprano
On Mon, 07 Oct 2013 15:47:26 -0700, Mark Janssen wrote: > I challenge you to get > down to the machine code in scheme and formally describe how it's doing > both. For which machine? Or are you assuming that there's only one machine code that runs on all computing devices? Frankly, asking some

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Mark Janssen
>> That's fine. My point was: you can't at the same time have full >> dynamicity *and* procedural optimizations (like tail call opt). >> Everybody should be clear about the trade-off. > > Your wrong. Full dynamics is not in contradiction with tail call > optimisation. Scheme has already done it for

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Piet van Oostrum
Alain Ketterlin writes: > BTW, does the original callable object have a ref counter? Is it garbage > collected in that case? If not, would it be considered a bug? In CPython ALL objects have ref counters. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] -- https

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread MRAB
On 07/10/2013 18:57, Antoon Pardon wrote: Op 07-10-13 19:15, Alain Ketterlin schreef: I want to consider here what it would mean to concretely implement the abstract notion 'disallow rebinding of function names' and show what would be behind calling the idea 'not feasible'. Again, I'm more con

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread random832
all optimization requires not keeping the intervening stack frames around, in _any_ form, so as to allow arbitrarily deep recursion without ever having the possibility of a stack overflow. An implementation which reduced but did not eliminate the space used per call would not be worthwhile because it

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread random832
ve introduced the idea of _further_ optimizations, transforming "near" tail recursion (i.e. return self()+1) into tail recursion, and _that_ depends on knowing the identity of the function (though arguably that could be accounted for at the cost of including dead code for the path that as

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Terry Reedy
On 10/7/2013 1:15 PM, Alain Ketterlin wrote: Terry Reedy writes: 3. Python does not mandate how namespaces are implemented. CPython uses both dicts and, for function local namespaces, internal C arrays. So 'names' in code can become either string keys for dicts or integer indexes for arrays.

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Antoon Pardon
Op 07-10-13 19:15, Alain Ketterlin schreef: I want to consider here what it would mean to concretely implement the abstract notion 'disallow rebinding of function names' and show what would be behind calling the idea 'not feasible'. Again, I'm more concerned about the function than about the na

Re: Tail recursion to while iteration in 2 easy steps

2013-10-07 Thread Alain Ketterlin
Terry Reedy writes: > On 10/4/2013 5:49 AM, Alain Ketterlin wrote: > >> I think allowing rebinding of function names is extremely strange, > > Steven already countered the 'is extremely strange' part by showing > that such rebinding is common, generally useful, and only occasionally > dodgy and a

Re: Tail recursion to while iteration in 2 easy steps

2013-10-05 Thread Antoon Pardon
Op 04-10-13 23:14, Terry Reedy schreef: On 10/4/2013 6:46 AM, Ian Kelly wrote: On the other hand, if you start optimizing every tail call and not just the recursive functions, then I can see where that could start to get problematic for debugging -- as arbitrary functions get removed from the s

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread Terry Reedy
On 10/4/2013 5:49 AM, Alain Ketterlin wrote: I think allowing rebinding of function names is extremely strange, Steven already countered the 'is extremely strange' part by showing that such rebinding is common, generally useful, and only occasionally dodgy and a candidate for being blocked.

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread Terry Reedy
On 10/4/2013 6:46 AM, Ian Kelly wrote: On the other hand, if you start optimizing every tail call and not just the recursive functions, then I can see where that could start to get problematic for debugging -- as arbitrary functions get removed from the stack traces just because they happened to

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread Duncan Booth
Ian Kelly wrote: > On Fri, Oct 4, 2013 at 4:41 AM, Ian Kelly wrote: >> There is no doubt that it's a tail call. Whether it is recursion is >> irrelevant to optimizing it. The reason we talk about "tail call >> recursion" specifically is because the recursi

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread Jussi Piitulainen
if it is just updates the > >> arguments and jumps to the start of the code block. > > > > Tail call optimization doesn't involve verification that the > > function is calling itself; you just have to verfify that the > > call is in tail position. > &g

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread rusi
On Thursday, October 3, 2013 10:57:48 PM UTC+5:30, Ravi Sahni wrote: > On Wed, Oct 2, 2013 at 10:46 AM, rusi wrote: > > 4. There is a whole spectrum of such optimizaitons -- > > 4a eg a single-call structural recursion example, does not need to push > > return address on the

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread Steven D'Aprano
On Fri, 04 Oct 2013 11:49:26 +0200, Alain Ketterlin wrote: > I think allowing rebinding of function names is extremely strange, It's not, it's quite common. Functions in Python are first-class values, and we can do things like this: from somelibrary import somethingwithalonglongname as shortnam

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread Ian Kelly
On Fri, Oct 4, 2013 at 4:41 AM, Ian Kelly wrote: > There is no doubt that it's a tail call. Whether it is recursion is > irrelevant to optimizing it. The reason we talk about "tail call > recursion" specifically is because the recursive case is the one that > makes

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread Ian Kelly
as the current function and if it is just updates the >>> arguments and jumps to the start of the code block. >> >> Tail call optimization doesn't involve verification that the >> function is calling itself; you just have to verfify that the >> call is in tail

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread Duncan Booth
d jumps to the start of the code block. > > Tail call optimization doesn't involve verification that the > function is calling itself; you just have to verfify that the > call is in tail position. You misunderstood me. As usually implemented tail call recursion doesn't requ

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread Alain Ketterlin
Mark Janssen writes: > def fact(n): return 1 if n <= 1 else n * fact(n-1) >> class Strange: >> ... >> def __le__(dummy): >> global fact >> fact = someotherfun # this is "binding" >> return false >> You cannot prevent this in python. > No, but you can't prevent a lot of bad

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread 88888 Dihedral
On Thursday, October 3, 2013 5:33:27 AM UTC+8, Terry Reedy wrote: > On 10/2/2013 8:31 AM, random...@fastmail.us wrote: > > > On Tue, Oct 1, 2013, at 17:30, Terry Reedy wrote: > > >> Part of the reason that Python does not do tail call optimization is > > >&

Re: Tail recursion to while iteration in 2 easy steps

2013-10-03 Thread Steven D'Aprano
On Thu, 03 Oct 2013 10:09:25 -0400, random832 wrote: > Speaking of assumptions, I would almost say that we should make the > assumption that operators (other than the __i family, and > setitem/setattr/etc) are not intended to have visible side effects. This > would open a _huge_ field of potential

Re: Tail recursion to while iteration in 2 easy steps

2013-10-03 Thread Steven D'Aprano
On Wed, 02 Oct 2013 22:41:00 -0400, Terry Reedy wrote: > I am referring to constant-value objects included in the code object. > >>> def f(): return (1,2,3) > > >>> f.__code__.co_consts > (None, 1, 2, 3, (1, 2, 3)) Okay, now that's more clear. I didn't understand what you meant before. So lon

Literal syntax for frozenset, frozendict (was: Tail recursion to while iteration in 2 easy steps)

2013-10-03 Thread Ben Finney
random...@fastmail.us writes: > Hey, while we're on the subject, can we talk about frozen(set|dict) > literals again? I really don't understand why this discussion fizzles > out whenever it's brought up on python-ideas. Can you start us off by searching for previous threads discussing it, and sum

Re: Tail recursion to while iteration in 2 easy steps

2013-10-03 Thread Terry Reedy
On 10/2/2013 10:34 PM, Steven D'Aprano wrote: You are both assuming that LOAD_CONST will re-use the same tuple (1, 2, 3) in multiple places. No I did not. To save tuple creation time, a pre-compiled tuple is reused when its display expression is re-executed. If I had been interested in multi

Re: Tail recursion to while iteration in 2 easy steps

2013-10-03 Thread Ravi Sahni
On Wed, Oct 2, 2013 at 10:46 AM, rusi wrote: > 4. There is a whole spectrum of such optimizaitons -- > 4a eg a single-call structural recursion example, does not need to push > return address on the stack. It only needs to store the recursion depth: > > If zero jump to outside ret

Re: Tail recursion to while iteration in 2 easy steps

2013-10-03 Thread Neil Cerutti
On 2013-10-03, Duncan Booth wrote: >> How do know that either "<=" or "*" didn't rebind the name >> "fact" to something else? I think that's the main reason why >> python cannot apply any procedural optimization (even things >> like inlining are impossible, or possible only under very >> conservat

Re: Tail recursion to while iteration in 2 easy steps

2013-10-03 Thread Duncan Booth
Alain Ketterlin wrote: > Terry Reedy writes: > >> Part of the reason that Python does not do tail call optimization is >> that turning tail recursion into while iteration is almost trivial, >> once you know the secret of the two easy steps. Here it is. >> >&g

Re: Tail recursion to while iteration in 2 easy steps

2013-10-03 Thread random832
On Wed, Oct 2, 2013, at 22:34, Steven D'Aprano wrote: > You are both assuming that LOAD_CONST will re-use the same tuple > (1, 2, 3) in multiple places. But that's not the case, as a simple test > will show you: >>> def f(): ... return (1, 2, 3) >>> f() is f() True It does, in fact, re-use it

Re: Tail recursion to while iteration in 2 easy steps

2013-10-03 Thread random832
On Wed, Oct 2, 2013, at 21:46, MRAB wrote: > > The difference is that a tuple can be reused, so it makes sense for the > > comiler to produce it as a const. (Much like the interning of small > > integers) The list, however, would always have to be copied from the > > compile-time object. So that

Re: Tail recursion to while iteration in 2 easy steps

2013-10-03 Thread random832
On Wed, Oct 2, 2013, at 17:33, Terry Reedy wrote: > 5. Conversion of apparent recursion to iteration assumes that the > function really is intended to be recursive. This assumption is the > basis for replacing the recursive call with assignment and an implied > internal goto. Th

Re: Tail recursion to while iteration in 2 easy steps

2013-10-02 Thread Chris Angelico
On Thu, Oct 3, 2013 at 12:34 PM, Steven D'Aprano wrote: > py> def f(): > ... a = (1, 2, 3) > ... b = (1, 2, 3) > ... return a is b > ... > py> f() # Are the tuples the same object? > False That just means the compiler doesn't detect reuse of the same tuple. But compare: >>> def f():

Re: Tail recursion to while iteration in 2 easy steps

2013-10-02 Thread Terry Reedy
an find versions that lack the last item. -- The language is as conservative about mandating optimizations as the implementation is about doing them. I consider making None, False, True be un-rebindable keynames to be an optimization. This is not even for the other singletons Ellipsis

Re: Tail recursion to while iteration in 2 easy steps

2013-10-02 Thread Terry Reedy
On 10/2/2013 9:46 PM, MRAB wrote: On 03/10/2013 02:39, Dave Angel wrote: On 2/10/2013 21:24, Steven D'Aprano wrote: On Wed, 02 Oct 2013 18:17:06 -0400, Terry Reedy wrote: CPython core developers have be very conservative about what tranformations they put into the compiler. (1,2,3) can alway

Re: Tail recursion to while iteration in 2 easy steps

2013-10-02 Thread Steven D'Aprano
On Thu, 03 Oct 2013 02:46:53 +0100, MRAB wrote: > On 03/10/2013 02:39, Dave Angel wrote: >> On 2/10/2013 21:24, Steven D'Aprano wrote: >> >>> On Wed, 02 Oct 2013 18:17:06 -0400, Terry Reedy wrote: >>> CPython core developers have be very conservative about what tranformations they put in

Re: Tail recursion to while iteration in 2 easy steps

2013-10-02 Thread MRAB
On 03/10/2013 02:39, Dave Angel wrote: On 2/10/2013 21:24, Steven D'Aprano wrote: On Wed, 02 Oct 2013 18:17:06 -0400, Terry Reedy wrote: CPython core developers have be very conservative about what tranformations they put into the compiler. (1,2,3) can always be compiled as a constant, and so

Re: Tail recursion to while iteration in 2 easy steps

2013-10-02 Thread Dave Angel
On 2/10/2013 21:24, Steven D'Aprano wrote: > On Wed, 02 Oct 2013 18:17:06 -0400, Terry Reedy wrote: > >> CPython core developers have be very conservative about what >> tranformations they put into the compiler. (1,2,3) can always be >> compiled as a constant, and so it is. [1,2,3] might or might

  1   2   3   4   5   6   >