Updating Variables

How do I change the state of a variable in Lasp?

Updating variables takes a variable identifier, an acceptable "mutation", and an actor identifier.

  • Variable identifier should be the identifier returned from a declare operation.
  • Mutations are possible mutations for the datatype: this is data type specific. For example, on the state_orset, add and rmv are possible mutations.
  • Actor identifier should identify this actor uniquely in the system: this is used to detect concurrent operations from different actors in the system, and it's assumed that each actor acts sequentially.

Here, we've added the value 1 to the set on this local replica. Eventually, all of the nodes in the system will see this value 1 in the set, but it might take some time before that happens.

> lasp:update({<<"set">>, state_orset}, {add, 1}, self()).                    

We can now see that the set reflects the added element.

> {ok, Value1} = lasp:query({<<"set">>, state_orset}), sets:to_list(Value1).