{"_id":"58e6b282b1eece19008b7e63","project":"5612c2a00fbdb60d00e4c7d1","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"},"user":"5612c290c0731b0d00625078","__v":0,"githubsync":"","parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-04-06T21:26:26.789Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"To read variables at a particular point in time, you can use the query command provided by Lasp.  This command will return the instantaneous value of the variable, and is not guaranteed to be deterministic or monotonic.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"> lasp:query({<<\\\"set\\\">>, state_orset}).\\n{ok,{set,0,16,16,8,80,48,\\n         {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},\\n         {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}}\",\n      \"language\": \"erlang\"\n    }\n  ]\n}\n[/block]\nIf you'd like to have a function executed every time a variable changes, Lasp provides a stream operator as well.  This will ensure that the function is executed each time the value of the variable changes **monotonically**; however, the function will does not guarantee that the value provided will be monotonic. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"> Function = fun(V) -> V end, \\n> lasp:stream({<<\\\"set\\\">>, state_orset}, Function).\\nok\",\n      \"language\": \"erlang\"\n    }\n  ]\n}\n[/block]","excerpt":"How can I read the value of a variable in Lasp?","slug":"reading-variables","type":"basic","title":"Reading Variables"}

Reading Variables

How can I read the value of a variable in Lasp?

To read variables at a particular point in time, you can use the query command provided by Lasp. This command will return the instantaneous value of the variable, and is not guaranteed to be deterministic or monotonic. [block:code] { "codes": [ { "code": "> lasp:query({<<\"set\">>, state_orset}).\n{ok,{set,0,16,16,8,80,48,\n {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},\n {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}}", "language": "erlang" } ] } [/block] If you'd like to have a function executed every time a variable changes, Lasp provides a stream operator as well. This will ensure that the function is executed each time the value of the variable changes **monotonically**; however, the function will does not guarantee that the value provided will be monotonic. [block:code] { "codes": [ { "code": "> Function = fun(V) -> V end, \n> lasp:stream({<<\"set\">>, state_orset}, Function).\nok", "language": "erlang" } ] } [/block]