Constants

You want numbers? We got numbers. You want strings? We got strings. You want complex numbers, we got complex numbers! Constants are a fast way to place data into a document. For instance, the following code outlines some basic constants:

#we_got_constants {
  int x = 123;
  int y = 0x04;
  double z = 3.14;
  bool b = true;
  principal c = @no_one;
  complex cx = 1 + @i;
}

Details

There are a variety of ways to conjure up constants. The following table illustrates examples:

typesyntaxexamples
bool(true, false)false, true
int[0-9]+42, 123, 0
int0x[0-9a-fA-F]+0xff, 0xdeadbeef
double[0-9].?[0-9]([eE](0-9)+)?3.14, 10e19, 2.72e10
string"(^"escape)*"
label#[a-z]+#foo, #start
principal@no_one@no_one
maybe<?>@maybe<Type>@maybe<int>
maybe(?)@maybe(Expr)@maybe(123)
complex@i1 + @i

@who is executing

The @who constant refers to the principal that is executing the current code.

@context of the caller

Within static policies, document constructors and events, and message handlers there is constant @context which is useful for getting access to the origin and ip or the caller.

@web's @parameters and @headers

The web handler has access to the parsed query string and HTTP headers respectively via the @parameters and @headers constants. @parameters is a dynamic with the query string converted to JSON. @headers is a map<string,string>.

Bubble's @viewer

A privacy bubble can access viewer state via the @viewer which behaves like a message.

Dynamic @null

The default dynamic type has a value of "null" which is represented via @null.

String escaping

A character following a backslash (\) is an escape sequence within a string, and it is an escape for the parser to inject special characters. For instance, if you are parsing a string initiated by double quotes, then how does one get a double quote into the string? Well, that's what the escape is for. Adama's strings support the following escape sequences:

escape codebehavior
\ta tab character
\ba backspace character
\na newline
\ra carriage return
\fa form feed
"a double quote (")
\\a backslash character (\)
\uABCDa unicode character formed by the four adjoined hex characters after the \u