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

[REBOL] Re: Static Variable Inside a Function

From: sunandadh:aol at: 2-Dec-2002 14:40

> Is there a way to have a Static Variable' C-like inside a function to > count the number of time a function is called ?
> you can use e.g. SFUN from
It's actual at (among other places) I hacked out a way of doing this a while ago -- not as generic as Ladislav's or as Rebolish as Romano's, but it gets the job done: my-func: func [/local s-vars] [ ;; initialise static variables s-vars: [] if 0 = length? s-vars [insert s-vars 0] ;; first entry is invocation count ;; add one to count s-vars/1: s-vars/1 + 1 print s-vars/1 ] ;; func ;; sample run loop 5 [my-func] Sunanda