{"_id":"58e6b2f6a8b43a2500fbd848","parentDoc":null,"project":"5612c2a00fbdb60d00e4c7d1","user":"5612c290c0731b0d00625078","__v":0,"category":{"_id":"58e6b68eb1eece19008b81fe","project":"5612c2a00fbdb60d00e4c7d1","version":"5612c2a00fbdb60d00e4c7d4","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-04-06T21:43:42.570Z","from_sync":false,"order":1,"slug":"api","title":"Lasp"},"version":{"_id":"5612c2a00fbdb60d00e4c7d4","__v":7,"project":"5612c2a00fbdb60d00e4c7d1","createdAt":"2015-10-05T18:34:08.611Z","releaseDate":"2015-10-05T18:34:08.611Z","categories":["5612c2a10fbdb60d00e4c7d5","58e6b64bc397de1b00173c09","58e6b68eb1eece19008b81fe","58e6b6d185ec873100be9734","58f5e5c2616bbb1b00d54c15","58f5eaa74c413f19007a2858","58f767a79c723f19004e1ca9"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.0.1","version":"0.0.1"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-04-06T21:28:22.423Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"Updating variables takes a variable identifier, an acceptable \"mutation\", and an actor identifier.\n\n* Variable identifier should be the identifier returned from a `declare` operation.\n* Mutations are possible mutations for the datatype: this is data type specific.  For example, on the `state_orset`, `add` and `rmv` are possible mutations.\n* 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.\n\nHere, 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.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"> lasp:update({<<\\\"set\\\">>, state_orset}, {add, 1}, self()).                    \\n{ok,{{<<\\\"set\\\">>,state_orset},\\n     state_orset,\\n     [{clock,[{<<170,227,142,126,63,64,19,227,195,66,39,125,58,\\n                 195,75,134,148,109,168,...>>,\\n               2}]}],\\n     {state_orset,[{1,\\n                    [{<<113,27,18,231,88,110,93,46,166,1,38,253,67,32,51,44,\\n                        ...>>,\\n                      true}]}]}}}\\n\\n\",\n      \"language\": \"erlang\"\n    }\n  ]\n}\n[/block]\nWe can now see that the set reflects the added element.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"> {ok, Value1} = lasp:query({<<\\\"set\\\">>, state_orset}), sets:to_list(Value1).\\n[1]\",\n      \"language\": \"erlang\"\n    }\n  ]\n}\n[/block]","excerpt":"How do I change the state of a variable in Lasp?","slug":"updating-variables","type":"basic","title":"Updating Variables"}

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. [block:code] { "codes": [ { "code": "> lasp:update({<<\"set\">>, state_orset}, {add, 1}, self()). \n{ok,{{<<\"set\">>,state_orset},\n state_orset,\n [{clock,[{<<170,227,142,126,63,64,19,227,195,66,39,125,58,\n 195,75,134,148,109,168,...>>,\n 2}]}],\n {state_orset,[{1,\n [{<<113,27,18,231,88,110,93,46,166,1,38,253,67,32,51,44,\n ...>>,\n true}]}]}}}\n\n", "language": "erlang" } ] } [/block] We can now see that the set reflects the added element. [block:code] { "codes": [ { "code": "> {ok, Value1} = lasp:query({<<\"set\">>, state_orset}), sets:to_list(Value1).\n[1]", "language": "erlang" } ] } [/block]