Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a global variable in Opa?

Tags:

opa

In MLState's new programming language Opa, is it possible to create a global variable?

like image 601
J D Avatar asked Jun 23 '11 21:06

J D


1 Answers

Opa is a functional language so there are no global variables in the language. However, one can achieve a similar behavior with Mutable. At top-level one declares the value with:

global_var = Mutable.make(initial_value)

where initial_value is the initial value for the variable (of some type t). Then one can retrieve the value with:

global_var.get()

and set it with:

global_var.set(new_value)

More information in the Opa API overview.

Note however, that this mechanism should be used only in special situations; the primary device of encapsulating state in Opa are its distributed sessions (see the Opa manual for more on that subject).

like image 105
akoprowski Avatar answered Oct 18 '22 10:10

akoprowski