-
Notifications
You must be signed in to change notification settings - Fork 2
Data Types
Ultraviolet provides a set of built-in data types, including numbers, strings, boolean values, functions, and special utility types.
Because Ultraviolet is a statically and strongly typed language, every value has a well-defined type that is verified during type checking.
<i8 /><i16 /><i32 /><i64 />
<u8 /><u16 /><u32 /><u64 />
<f32 /><f64 />
<bool />
Boolean values may only contain 0 | 1 or false | true.
<str />
See the Functions section for more information.
<fn>...</fn>
-
<null />— represents a null value. This type may be removed in future versions of the language. -
<void />— represents the absence of a value.
A value instance is created by placing a valid value inside the corresponding type tag.
<u8>5</u8>This creates a value of type u8 with the value 5.
Attempting to create a value that does not match the target type will result in a type-checking error.
<i32>-100</i32>
<f64>3.1415926535</f64>
<bool>1</bool>
<str>Hello World!</str><u8>-5</u8>
<i32>Hello</i32>All of the examples above will produce type-checking errors.
The str type supports labels, which allow string literals to safely contain text that would otherwise be interpreted as Ultraviolet syntax.
A label is specified after the tag name using the following format:
<str-my_label>
...
</str-my_label>The interpreter will only treat a closing tag with the same label as the end of the string.
<str-random_label>
This string contains <str> as plain text!
</str-random_label>In this case, the inner <str> sequence becomes part of the string value rather than being parsed as a nested tag.
Labels are useful when storing:
- Source code
- XML fragments
- Templates
- Documentation
- Any text that may contain Ultraviolet tags
Without labels, such content could prematurely terminate the string.
Unlike primitive value types, special types do not accept content.
<null />
<void /><null>value</null>
<void>value</void>These forms are not allowed.
Types can be used not only to create values, but also to explicitly declare types.
Whenever the interpreter expects a type declaration, the type must be provided as a self-closing tag.
<let>
<name>...</name>
<type>
<i32 />
</type>
<value>
...
</value>
</let>In this context, <i32 /> describes a type rather than a value.
Note
Type declarations never contain values.
See the References section for more information.
Any type can be marked as a reference type by adding the ref modifier.
<str ref />
<i32 ref />
<f64 ref />A reference type stores a reference to a value instead of the value itself.
Reference types are commonly used when passing mutable data between functions or when working directly with memory references.
Created by Ultraviolet lang org, AndcoolSystems