tags:

views:

29

answers:

2

This shows how to have a static variable inside an object or context: http://www.mail-archive.com/[email protected]/msg04764.html

But the scope is too large for some needs, is it possible to have a static variable inside an object function ?

+1  A: 

In R3, use a closure rather than a func.

In R2, fake it by having a block that contains your static values, eg :

f: func [
   /local sb
][
     ;; define and initialise the static block
 sb: [] if 0 = length? sb [append sb 0]

     ;; demonstate its value persists across calls
 sb/1: sb/1 + 1
 print sb
 ]

    ;; sample code to demonstrate function
 loop 5 [f]
 == 1
 == 2
 == 3
 == 4
 == 5
Sunanda
Clever, thanks. (I'm still using R2 as R3 doesn't seem to work with my pc)
Rebol Tutorial
+1  A: 

Or you can use

funct/with
, or my
funcs
function.

Ladislav