Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: REBOL Enhancement Proposals (REPs)

From: joel:neely:fedex at: 27-Sep-2001 13:38

Hi, Ladislav, Ladislav Mecir wrote:
> > > > > > BTW, is your Perl implementation correct? > > > > > > > ... That is, the equivalent of the Perl > > > > > > > > for (my $i = 1; $i < $#a; ++$i) { > > > > $a[$i] = ($a[$i-1] + $a[$i] + $a[$i+1])/3; > > > > } > > > > > > > > Yes, AFAICT. It even agrees with uSoft XL! ;-) > > > > What looked suspicious to you? > > > > -jn- > > > > I don't know Perl enough, but the difference between: > > ;$i < $#a; for Perl and the C ; i < sizeof(a)/sizeof(double) - 2; > > looked suspicious to me. >
The bug is in my composed-at-the-keyboard version for TLWMNBN. Both Perl and TLWMNBN use zero-origin indexing, which means that an array of length N has indices 0 .. N-1. This, in turn means that the "interior" elements have indices 1 .. N-2. The Perl construct $#a provides the last index of the array @a, so from 1 while < $#a really is correct. The other version should have read (in part) ... < sizeof(a)/sizeof(double) - 1 ... (or the equivalent ... <= sizeof(a)/sizeof(double) - 2 ... meaning that my typo was either the substitution of "2" for "1" or the omission of "=" ;-) You can draw your own conclusions about which of Perl and TLWMNBN I spend more time in (or pay more attention to) these days! Thanks for catching the error! -jn- -- This sentence contradicts itself -- no actually it doesn't. -- Doug Hofstadter joel<dot>neely<at>fedex<dot>com