Re: Understanding recursion

2009-07-10 Thread Ken Slater
Dermot wrote: >Hi, > >I was reading Higher Order Perl[1] last night and, dishearteningly, >got stuck on chapter one. > >Mark Dominus offers the following as a binary string conversion >example of how recursion can work. > > >use strict; >use warnings; > >my $bstr = binary(37); >print "$bstr\n";

Re: Understanding recursion

2009-07-10 Thread Dermot
2009/7/10 Telemachus : > On Fri Jul 10 2009 @  9:26, Dermot wrote: >> The algorithm works perfectly but my understanding of it's workings is amiss. >> >> When I look at this I see $E initialised and then concatenate with the >> the modulus of > > It helps for me to walk through it visually, indenti

Re: Understanding recursion

2009-07-10 Thread Telemachus
On Fri Jul 10 2009 @ 9:26, Dermot wrote: > The algorithm works perfectly but my understanding of it's workings is amiss. > > When I look at this I see $E initialised and then concatenate with the > the modulus of > 37 % 2 =1 > 18 % 2 = 0 > 9 % 2 = 1 > 4 % 2 = 0 > 2 % 2 = 0 > > That by my reckoni

Re: Understanding recursion

2009-07-10 Thread Shawn H. Corey
On Fri, 2009-07-10 at 13:42 +0100, Dermot wrote: > Why is $E getting assigned the value from $k? my $E = binary($k); I said $E will be assigned the string that represents $k, not it's value. > $E is initialised and > then assigned the return value of the binary(18) during the first > invocation

Re: Understanding recursion

2009-07-10 Thread Dermot
2009/7/10 Shawn H. Corey : > On Fri, 2009-07-10 at 09:26 +0100, Dermot wrote: >> The algorithm works perfectly but my understanding of it's workings is amiss. >> >> When I look at this I see $E initialised and then concatenate with the >> the modulus of >> 37 % 2 =1 >> 18 % 2 = 0 >> 9 % 2 = 1 >> 4

Re: Understanding recursion

2009-07-10 Thread Shawn H. Corey
On Fri, 2009-07-10 at 09:26 +0100, Dermot wrote: > The algorithm works perfectly but my understanding of it's workings is amiss. > > When I look at this I see $E initialised and then concatenate with the > the modulus of > 37 % 2 =1 > 18 % 2 = 0 > 9 % 2 = 1 > 4 % 2 = 0 > 2 % 2 = 0 > > That by my

Understanding recursion

2009-07-10 Thread Dermot
Hi, I was reading Higher Order Perl[1] last night and, dishearteningly, got stuck on chapter one. Mark Dominus offers the following as a  binary string conversion example of how recursion can work. use strict; use warnings; my $bstr = binary(37); print "$bstr\n";                 # prints 10010