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 library.

Let's declare a set named <<"set">> (an Erlang binary) that's a CRDT state-based Observed-Remove Set.

> {ok, {Id, Type, Metadata, Value}} = lasp:declare({<<"set">>, state_orset}, state_orset).

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.