{"_id":"58e6b1af4dae652300f94945","project":"5612c2a00fbdb60d00e4c7d1","user":"5612c290c0731b0d00625078","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"},"parentDoc":null,"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"},"__v":1,"updates":["58f10f3718bded1b00f281ad"],"next":{"pages":[],"description":""},"createdAt":"2017-04-06T21:22:55.373Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"Variables in Lasp are identified using a tuple of a globally unique identifier for the variable and the variable's type.  Each variable needs to have a type that points to an implementation of a CRDT from our [types](https://www.github.com/lasp-lang/types) library.  \n\nLet's declare a set named `<<\"set\">>` (an Erlang binary) that's a CRDT state-based Observed-Remove Set.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"> {ok, {Id, Type, Metadata, Value}} = lasp:declare({<<\\\"set\\\">>, state_orset}, state_orset).\\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               1}]}],\\n     {state_orset,[]}}}\",\n      \"language\": \"erlang\"\n    }\n  ]\n}\n[/block]\nHere, after the `declare` call is issued, a few things happen:\n\n* A tuple is returned containing the identifier, type, metadata about the object, and the object's value.\n* The value of the variable is defaulted at the **bottom** value for the CRDT: in this case, the set's bottom value is the empty set.\n* Each node in the system will have a **different** value for the variable, and eventually converge after anti-entropy is performed.","excerpt":"How do you define new variables in the system?","slug":"declaring-variables","type":"basic","title":"Declaring Variables"}

Declaring Variables

How do you define new variables in the system?

Variables in Lasp are identified using a tuple of a globally unique identifier for the variable and the variable's type. Each variable needs to have a type that points to an implementation of a CRDT from our [types](https://www.github.com/lasp-lang/types) library. Let's declare a set named `<<"set">>` (an Erlang binary) that's a CRDT state-based Observed-Remove Set. [block:code] { "codes": [ { "code": "> {ok, {Id, Type, Metadata, Value}} = lasp:declare({<<\"set\">>, state_orset}, state_orset).\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 1}]}],\n {state_orset,[]}}}", "language": "erlang" } ] } [/block] Here, after the `declare` call is issued, a few things happen: * A tuple is returned containing the identifier, type, metadata about the object, and the object's value. * The value of the variable is defaulted at the **bottom** value for the CRDT: in this case, the set's bottom value is the empty set. * Each node in the system will have a **different** value for the variable, and eventually converge after anti-entropy is performed.