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

Phillpe:
> Is there a way to have a Static Variable' C-like inside a function to > count the number of time a function is called ?
Ladislav:
> you can use e.g. SFUN from http://www.rebolforces.com/highfun.r
It's actual at (among other places) http://www.rebol.org/general/sfun.html 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