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

[REBOL] Re: Rolling your own ideal looper: does Repeat still have a bug?

From: g:santilli:tiscalinet:it at: 26-Aug-2000 14:41

Hello [galtbarber--MailAndNews--com]! On 26-Ago-00, you wrote: g> See attached rebol file and output. How about:
>> ideal-looper: func [
[ 'element [word!] [ 'index [word!] [ series [series!] [ code [block!] [ /local f [ ] [ [ f: func reduce [element index] code [ repeat i length? series [f series/:i i] [ ]
>> ideal-looper char pos "hello" [print [pos char]]
1 h 2 e 3 l 4 l 5 o Much simpler, isn't it? :-) You get a new context and the correct bindings for free creating a function. However, there really seems to be some problems with recursion and REPEAT:
>> ideal-looper char pos s: "hello" [
[ prin [pos char] [ ideal-looper char pos s [prin " " prin char] [ prin newline [ ] 1 h h e l l o 6 none h e l l o 6 none h e l l o 6 none h e l l o 6 none h e l l o But:
>> repeat i 10 [prin i repeat i 10 [prin " " prin i] prin newline]
1 1 2 3 4 5 6 7 8 9 10 2 1 2 3 4 5 6 7 8 9 10 3 1 2 3 4 5 6 7 8 9 10 4 1 2 3 4 5 6 7 8 9 10 5 1 2 3 4 5 6 7 8 9 10 6 1 2 3 4 5 6 7 8 9 10 7 1 2 3 4 5 6 7 8 9 10 8 1 2 3 4 5 6 7 8 9 10 9 1 2 3 4 5 6 7 8 9 10 10 1 2 3 4 5 6 7 8 9 10 which makes me wonder... Anyway, using FOR:
>> ideal-looper: func [
[ 'element [word!] [ 'index [word!] [ series [series!] [ code [block!] [ /local f [ ] [ [ f: func reduce [element index] code [ for i 1 length? series 1 [f series/:i i] [ ]
>> ideal-looper char pos s: "hello" [
[ prin [pos char] [ ideal-looper char pos s [prin " " prin char] [ prin newline [ ] 1 h h e l l o 2 e h e l l o 3 l h e l l o 4 l h e l l o 5 o h e l l o I'd suggest reporting that to feedback. HTH, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/