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

[REBOL] Re: Translate this code into real Rebol?

From: joel::neely::fedex::com at: 23-Jan-2002 23:40

Hi, Brett, Brett Handley wrote:
> make context [fibohelp: none] [ > set 'fibonacci func [n [integer!] /test][ > fibohelp: func [n [integer!] /local a b] [ > a: 0 b: 1 > while [n > 0] [a: (b: b + a) - a n: n - 1] > print ["by the way the value of test is:" mold test] > a > ] > either all [negative? n even? n] [ > - fibohelp abs n > ] [ > fibohelp abs n > ] > ] > ] > > The good thing is Fibohelp can utilise words from Fibonacci's > namespace... The assumed thing is that there is no redefinition > occurring every call. >
AFAICT that's a bad assumption, and the above is just a more complicated way of saying fibonacci: func [n [integer!] /local fibohelp] [ fibohelp: func [n [integer!] /local a b] [ a: 0 b: 1 while [n > 0] [a: (b: b + a) - a n: n - 1] a ] either all [negative? n even? n] [ - fibohelp abs n ][ fibohelp abs n ] ] which actually *does* redefine FIBOHELP every time FIBONACCI is invoked. Both of the above versions run about four and a half times slower than the version (posted earlier) created with USE. (I removed the /TEST refinement and related PRINT before running the timing tests so that I/O lag wouldn't affect the results.) -jn- -- ; sub REBOL {}; sub head ($) {@_[0]} REBOL [] # despam: func [e] [replace replace/all e ":" "." "#" "@"] ; sub despam {my ($e) = @_; $e =~ tr/:#/.@/; return "\n$e"} print head reverse despam "moc:xedef#yleen:leoj" ;