{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[]},"next":{"description":"","pages":[]},"title":"Declaring Variables","type":"basic","slug":"declaring-variables","excerpt":"How do you define new variables in the system?","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.","updates":["58f10f3718bded1b00f281ad"],"order":2,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"58e6b1af4dae652300f94945","project":"5612c2a00fbdb60d00e4c7d1","user":"5612c290c0731b0d00625078","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"},"createdAt":"2017-04-06T21:22:55.373Z","githubsync":"","parentDoc":null,"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"},"__v":1}

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.