Re: recursion depth problem

2007-04-23 Thread Michael Bentley
On Apr 23, 2007, at 1:57 AM, proctor wrote: > On Apr 22, 5:51 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: >> Oops! Note to self: *ALWAYS* try code before posting to a public >> forum :-( >> >> def binary(val, width): >> print '%10s = the sum of' % val >> for i in [2 ** x for x

Re: recursion depth problem

2007-04-23 Thread proctor
On Apr 22, 5:51 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: > Oops! Note to self: *ALWAYS* try code before posting to a public > forum :-( > > def binary(val, width): > print '%10s = the sum of' % val > for i in [2 ** x for x in range(width - 1, -1, -1)]: > a = v

Re: recursion depth problem

2007-04-22 Thread proctor
On Apr 22, 8:23 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > Steven Bethard <[EMAIL PROTECTED]> wrote: > >... > > > > > > import sys > > > def ch4(item, n=0): > > >if n < len(item): > > >if item[n] == '0': > > >item[n] = '1' > > >

Re: recursion depth problem

2007-04-22 Thread proctor
On Apr 22, 9:28 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On 22 Apr 2007 19:13:31 -0700, proctor <[EMAIL PROTECTED]> declaimed the > following in comp.lang.python: > > > > > :-) > > > this is good stuff. for learning especially! thank you again! > > Took me some time to find... M

Re: recursion depth problem

2007-04-22 Thread [EMAIL PROTECTED]
On Apr 22, 9:13�pm, proctor <[EMAIL PROTECTED]> wrote: > On Apr 22, 7:10 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > > > > > > > On 22 Apr 2007 17:06:18 -0700, proctor <[EMAIL PROTECTED]> declaimed the > > following in comp.lang.python: > > > > > � � else: > > > > � � � � # only one of carry

Re: recursion depth problem

2007-04-22 Thread Steven Bethard
Alex Martelli wrote: > Steven Bethard <[EMAIL PROTECTED]> wrote: >... >>> import sys >>> def ch4(item, n=0): >>>if n < len(item): >>>if item[n] == '0': >>>item[n] = '1' >>>print ''.join(item) >>>

Re: recursion depth problem

2007-04-22 Thread Alex Martelli
Steven Bethard <[EMAIL PROTECTED]> wrote: ... > > import sys > > def ch4(item, n=0): > >if n < len(item): > >if item[n] == '0': > >item[n] = '1' > >print ''.join(item) > >ch4(item) > >

Re: recursion depth problem

2007-04-22 Thread proctor
On Apr 22, 7:34 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: > proctor wrote: > > On Apr 22, 2:06 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: > >> proctor wrote: > >>> On Apr 22, 1:24 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: > On Apr 22, 2007, at 1:49 PM, proctor wrote: > > i have

Re: recursion depth problem

2007-04-22 Thread proctor
On Apr 22, 7:10 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On 22 Apr 2007 17:06:18 -0700, proctor <[EMAIL PROTECTED]> declaimed the > following in comp.lang.python: > > > > else: > > > # only one of carry in, b1, or b2 is set > > #or none is set! Missed t

Re: recursion depth problem

2007-04-22 Thread Steven Bethard
proctor wrote: > On Apr 22, 2:06 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >> proctor wrote: >>> On Apr 22, 1:24 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: On Apr 22, 2007, at 1:49 PM, proctor wrote: > i have a small function which mimics binary counting. it runs fine as > lon

Re: recursion depth problem

2007-04-22 Thread proctor
On Apr 22, 5:51 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Sun, 22 Apr 2007 17:37:05 -0500, Michael Bentley > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > > > Anything that can be done with recursion can be done without > > recursion. If you really wanted to mimic

Re: recursion depth problem

2007-04-22 Thread proctor
On Apr 22, 5:51 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: > Oops! Note to self: *ALWAYS* try code before posting to a public > forum :-( > > def binary(val, width): > print '%10s = the sum of' % val > for i in [2 ** x for x in range(width - 1, -1, -1)]: > a = v

Re: recursion depth problem

2007-04-22 Thread Michael Bentley
Oops! Note to self: *ALWAYS* try code before posting to a public forum :-( def binary(val, width): print '%10s = the sum of' % val for i in [2 ** x for x in range(width - 1, -1, -1)]: a = val / i print ' ' * 13 + '%s * (2 ** %s)' % (a, width)

Re: recursion depth problem

2007-04-22 Thread Michael Bentley
On Apr 22, 2007, at 5:47 PM, proctor wrote: > On Apr 22, 4:37 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: >> On Apr 22, 2007, at 4:08 PM, proctor wrote: >> >> >> >>> On Apr 22, 2:55 pm, [EMAIL PROTECTED] wrote: On Apr 22, 11:49 am, proctor <[EMAIL PROTECTED]> wrote: >> > hello, >> >>>

Re: recursion depth problem

2007-04-22 Thread proctor
On Apr 22, 5:05 pm, tac-tics <[EMAIL PROTECTED]> wrote: > Yes, you should use a for loop in this situation. > > Certain functional languages, such as Scheme and various LISP dialects > allow for what is called "tail recursion" which effectively eliminates > this problem by internally converting rec

Re: recursion depth problem

2007-04-22 Thread tac-tics
Yes, you should use a for loop in this situation. Certain functional languages, such as Scheme and various LISP dialects allow for what is called "tail recursion" which effectively eliminates this problem by internally converting recursion to iteration. Python isn't really cut out for heavy recurs

Re: recursion depth problem

2007-04-22 Thread proctor
On Apr 22, 4:37 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: > On Apr 22, 2007, at 4:08 PM, proctor wrote: > > > > > On Apr 22, 2:55 pm, [EMAIL PROTECTED] wrote: > >> On Apr 22, 11:49 am, proctor <[EMAIL PROTECTED]> wrote: > > >>> hello, > > >>> i have a small function which mimics binary countin

Re: recursion depth problem

2007-04-22 Thread Michael Bentley
On Apr 22, 2007, at 4:08 PM, proctor wrote: > On Apr 22, 2:55 pm, [EMAIL PROTECTED] wrote: >> On Apr 22, 11:49 am, proctor <[EMAIL PROTECTED]> wrote: >> >> >> >>> hello, >> >>> i have a small function which mimics binary counting. it runs >>> fine as >>> long as the input is not too long, but

Re: recursion depth problem

2007-04-22 Thread proctor
On Apr 22, 2:06 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: > proctor wrote: > > On Apr 22, 1:24 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: > >> On Apr 22, 2007, at 1:49 PM, proctor wrote: > > >>> i have a small function which mimics binary counting. it runs fine as > >>> long as the input i

Re: recursion depth problem

2007-04-22 Thread proctor
On Apr 22, 2:55 pm, [EMAIL PROTECTED] wrote: > On Apr 22, 11:49 am, proctor <[EMAIL PROTECTED]> wrote: > > > > > hello, > > > i have a small function which mimics binary counting. it runs fine as > > long as the input is not too long, but if i give it input longer than > > 8 characters it gives >

Re: recursion depth problem

2007-04-22 Thread half . italian
On Apr 22, 11:49 am, proctor <[EMAIL PROTECTED]> wrote: > hello, > > i have a small function which mimics binary counting. it runs fine as > long as the input is not too long, but if i give it input longer than > 8 characters it gives > > RuntimeError: maximum recursion depth exceeded in cmp > > i

Re: recursion depth problem

2007-04-22 Thread Steven Bethard
proctor wrote: > On Apr 22, 1:24 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: >> On Apr 22, 2007, at 1:49 PM, proctor wrote: >> >> >> >>> i have a small function which mimics binary counting. it runs fine as >>> long as the input is not too long, but if i give it input longer than >>> 8 characte

Re: recursion depth problem

2007-04-22 Thread proctor
On Apr 22, 1:24 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: > On Apr 22, 2007, at 1:49 PM, proctor wrote: > > > > > i have a small function which mimics binary counting. it runs fine as > > long as the input is not too long, but if i give it input longer than > > 8 characters it gives > > > Run

Re: recursion depth problem

2007-04-22 Thread Michael Bentley
On Apr 22, 2007, at 1:49 PM, proctor wrote: > i have a small function which mimics binary counting. it runs fine as > long as the input is not too long, but if i give it input longer than > 8 characters it gives > > RuntimeError: maximum recursion depth exceeded in cmp > > i'm not too sure what