{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[]},"next":{"description":"","pages":[]},"title":"Updating Variables","type":"basic","slug":"updating-variables","excerpt":"How do I change the state of a variable in Lasp?","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]","updates":[],"order":4,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"58e6b2f6a8b43a2500fbd848","parentDoc":null,"project":"5612c2a00fbdb60d00e4c7d1","user":"5612c290c0731b0d00625078","createdAt":"2017-04-06T21:28:22.423Z","__v":0,"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Lasp","slug":"api","order":1,"from_sync":false,"reference":false,"_id":"58e6b68eb1eece19008b81fe","project":"5612c2a00fbdb60d00e4c7d1","version":"5612c2a00fbdb60d00e4c7d4","__v":0,"createdAt":"2017-04-06T21:43:42.570Z"},"githubsync":"","version":{"version":"0.0.1","version_clean":"0.0.1","codename":"","is_stable":true,"is_beta":true,"is_hidden":false,"is_deprecated":false,"categories":["5612c2a10fbdb60d00e4c7d5","58e6b64bc397de1b00173c09","58e6b68eb1eece19008b81fe","58e6b6d185ec873100be9734","58f5e5c2616bbb1b00d54c15","58f5eaa74c413f19007a2858","58f767a79c723f19004e1ca9"],"_id":"5612c2a00fbdb60d00e4c7d4","createdAt":"2015-10-05T18:34:08.611Z","releaseDate":"2015-10-05T18:34:08.611Z","__v":7,"project":"5612c2a00fbdb60d00e4c7d1"}}
Updating Variables
How do I change the state of a variable in Lasp?