The sharedvars
module is an extension module. Its purpose is to provide new primitives to the Orchids language.
All variables are thread-local in Orchids: if you use you variable $x
in a rule, then only the current thread sees the values of $x
. The sharedvars
module allows one to create the equivalent of global variables, shared by all threads and all rules.
The name is slightly misleading: sharedvars are not variables, they are just entries in a global hash table. One creates a sharedvar by using the Set
configuration option, or by calling set_shared_var
, e.g., set_shared_var("my_database", "orchids.sql")
or set_shared_var("last_time_accessed", $time)
, and other threads can obtain the value by reading get_shared_var("my_database")
or get_shared_var("last_time_accessed")
respectively.
Configuration options
<module sharedvars>
HashSize
n: defines the size of the global hash size. Default is 1021.Set
name value: initialize sharedvar name to the string value (between quotes).
</module>
Primitives
set_shared_var
:str
,str
→int
set a sharedvar to a value- usage:
set_shared_var
(var-name, value)
sets the value of the sharedvar var-name to value, creating it if necessary - returns: 1 (true)
- usage:
get_shared_var
:str
→str
get a sharedvar’s value- usage:
get_shared_var
(var-name) - returns: the value of the sharedvar var-name if it exists, or the undefined null value otherwise
- usage:
del_shared_var
:str
→int
delete a sharedvar- usage:
del_shared_var
(var-name) - returns: 1 (true) if sharedvar var-name was successfully deleted, 0 (false) if sharedvar var-name did not exist
- usage: