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 ?
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 ?
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