Here's an example script and the console interaction with it, using the
value? concept.

First, the script:, %teststaticvars.r --

REBOL[]
either value? 'mystaticvar


    print ["old value" mystaticvar]
    mystaticvar: 0
    print ["new value" mystaticvar]
    ]
    [
    print "Setting mystaticvar"
    mystaticvar: 25
    ]

Now, here's the console interation.

>> unset [mystaticvar] ; to start with a "clean slate"; not needed if you're
sure 'mystatic has no value.
>> do %teststaticvars.r
Script: "Untitled" (none)
Setting mystaticvar
== 25

; Now, without exiting REBOL, run the script a second time. This time,
mystaticvar exists and has a value,
;  set when the script was first called -  It can be set to a new value.

>> do %teststaticvars.r
Script: "Untitled" (none)
old value 25
new value 0
>>


Russell [EMAIL PROTECTED]
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, February 09, 2000 2:09 PM
Subject: [REBOL] "static" variable Re:


>
> One possible way is for you to use "value?" in your script
> to see if that particular variable is already in use.  You
> may have this in your script:
>
> if not value? 'myvalue [ myvalue: 1 print "not declared" ]
>
> Another possible way is for the script to modify the actual file
> whenever it is run to keep your static value up to date.  That's
> probably not what you want but I've played with that concept
> before.
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, February 09, 2000 11:44 AM
> To: [EMAIL PROTECTED]
> Subject: [REBOL] "static" variable
>
>
> Hi,
>
> Does anyone know whether Rebol has such a kind of variable: you initialize
> this
> variable at the first time you run the script. In this script, the
variable
> will
> be modified to some value. If you run this script again, this variable
will
> preserve the value it has in last run.
>
> Thanks in advance.
>
> Tiana
>

Reply via email to