Vikari Language Documentation


Available since:  v0.7.0.

Null Type

The Null type represents the absence of a value. It is a special type that is a subtype of every other type. This allows variables of type Null to be assignable to variables of any type. So a null Integer is not the same as a null Float, as their inheritance hierarchies are different.

Nulls in Vikari have a length property. This enables a null value to carry more information in other languages, and makes them more useful. So an algorithm can convey something meaningful in the form of an integer value along with a null result.

There are three ways of writing a null literal value in Vikari: The first form is to use the null keyword. This produces a null value of length zero. The second form is to use a series of sequential underscores, known as a sword crystal. This produces a null value with a length equal to the number of underscores. The third form is to use a sword followed by a left square bracket _[ followed by an integer literal followed by a right square bracket followed by another sword ]_. This produces a null value with a length equal to the provided integer.

Declaring a variable without an initializer expression sets it to a null value of length zero. This is equivalent to using the null keyword. Variables declared with type Null inherit from AtonementCrystal. To test if a variable is null, use the comparison operators = or '= in conjunction with the null keyword. This will return true for null values of any length. To test instead for a null of a specific length, use a sword or null literal expression of the desired length for the comparison, instead.

Any variable can be assigned null after being assigned a non-null value using one of the three null literal values. A null variable's length can also be reassigned using one of the same three methods, as well.

Examples

The following demonstrates use of the Null type.

~:Eliding an initializer expression sets a variable to null.:~
foo:AtonementCrystal

~:Using the null keyword.:~
bar:AtonementCrystal << null

~:Using a sword.:~
baz:AtonementCrystal << ____

~:Using a null literal expression.:~
buzz:AtonementCrystal << __[ -1]__

~:Test that a variable is null, regardless of its length.:~
:[foo = null]:

~:Test that a variable is of a specified length.:~
:[bar = ____]:
:[bar = __[4]__]:

~:Test that a variable is not null.:~
:[baz '= null]: