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()).                    
{ok,{{<<"set">>,state_orset},
     state_orset,
     [{clock,[{<<170,227,142,126,63,64,19,227,195,66,39,125,58,
                 195,75,134,148,109,168,...>>,
               2}]}],
     {state_orset,[{1,
                    [{<<113,27,18,231,88,110,93,46,166,1,38,253,67,32,51,44,
                        ...>>,
                      true}]}]}}}

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

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