This appendix summarizes the interpreter-level built-ins documented in the Nex Reference. It is not intended to replace the full reference pages, but to give one compact place to look up the core types used throughout the tutorial.
| Name | Signature | Purpose |
|---|---|---|
print |
print(...args) |
Write values to interpreter output. |
println |
println(...args) |
Line-oriented output. |
type_of |
type_of(value): String |
Return runtime type name. |
type_is |
type_is(type_name: String, value): Boolean |
Check runtime type compatibility. |
sleep |
sleep(ms: Integer) |
Pause the current task for ms milliseconds. |
await_all |
await_all(tasks: Array[Task]) |
Block until all tasks in the array complete. |
await_any |
await_any(tasks: Array[Task]) |
Block until at least one task in the array completes. |
| Type | Main Features | Notes |
|---|---|---|
Function |
call0 through call32 |
Invocation protocol for function-like values. |
Comparable |
compare |
Ordering support for scalars and other comparable values. |
Any |
to_string, equals, hash, clone |
Root of every class. Every value has hash, so any type can be a map key or set element. |
Iterable[T] (deferred) |
cursor |
Anything across can walk. Array, Set, String and Map are Iterable. |
Cursor[T] (deferred) |
start, item, next, at_end |
One walk over an Iterable[T]; item returns a T. |
StringCommon operations:
lengthindex_ofsubstring(start, end)to_upper, to_lowerto_integer, to_realcontains, starts_with, ends_withtrim, replacechar_atsplitto_bytes (an Array[Byte] of the UTF-8 encoding), and create String.from_bytes(bytes) for the reversecompare, hash, cursorExample:
let s: String := " Nex "
print(s.trim().to_upper()) -- "NEX"
print(s.split(" ")) -- array of pieces
IntegerCommon operations:
to_stringabs, min, maxpickto_byte, to_integer16, to_integer32 (checked conversions to the fixed-width types)bitwise_left_shift, bitwise_right_shift, bitwise_logical_right_shiftbitwise_rotate_left, bitwise_rotate_rightbitwise_is_set, bitwise_set, bitwise_unsetbitwise_and, bitwise_or, bitwise_xor, bitwise_notplus, minus, times, divided_bycompare, hashInteger is a signed 64-bit integer on every backend, with checked arithmetic: overflow and division by zero raise. Bitwise operations use 32-bit integer semantics. Bit 0 is the least-significant bit. When calling a bitwise method on an integer literal, wrap the literal in parentheses:
print((5).bitwise_left_shift(1)) -- 10
print((6).bitwise_and(3)) -- 2
print((5).bitwise_is_set(0)) -- true
RealCommon operations:
to_stringabs, min, max, round, to_fixed, formatis_nan, is_infinite, is_finitecompare, hashReal is an IEEE-754 double; division by zero yields Infinity or NaN rather than raising (integer division by zero raises).
BooleanCommon operations:
to_stringand, or, notcompare, hashCharCommon operations:
to_stringto_upper, to_lowercompare, hashByteCommon operations:
to_string, to_hex, to_charto_integer, to_integer16, to_integer32min, maxbitwise_left_shift, bitwise_right_shift, bitwise_logical_right_shiftbitwise_rotate_left, bitwise_rotate_rightbitwise_is_set, bitwise_set, bitwise_unsetbitwise_and, bitwise_or, bitwise_xor, bitwise_notequals, compare, hashByte is an unsigned 8-bit integer (0 to 255) and the element type of String.to_bytes(). Write a literal with a u8 suffix: 200u8. It does not convert to or from Integer on its own — use Integer.to_byte() (which raises unless the value is in 0..255) and Byte.to_integer(). Arithmetic on a Byte gives an Integer. The bitwise methods work on 8 bits and return a Byte, so 195u8.bitwise_not() is 60u8; bit indexes must be 0..7.
let b: Byte := 195u8
print(b.to_hex()) -- "c3"
print(b.bitwise_not()) -- 60
print(b + 1) -- 196 (an Integer)
Integer16 and Integer32Both types have the same operations (T stands for the type itself):
to_string (optionally in base 2, 8, 10 or 16)to_integer, to_byte, to_integer16, to_integer32abs, min, max (each returns a T)bitwise_left_shift, bitwise_right_shift, bitwise_logical_right_shiftbitwise_rotate_left, bitwise_rotate_rightbitwise_is_set, bitwise_set, bitwise_unsetbitwise_and, bitwise_or, bitwise_xor, bitwise_notequals, compare, hashInteger16 is a signed 16-bit integer (-32768 to 32767) and Integer32 a signed 32-bit integer (-2147483648 to 2147483647). Write literals with an i16 or i32 suffix; a leading minus is part of the literal, so -5i16 is an Integer16. Neither converts implicitly to another integer type, and narrowing conversions raise an error if the value does not fit. Arithmetic gives an Integer. The bitwise methods work on, and wrap to, the type's own width: 0i16.bitwise_not() is -1i16, and 32767i16.bitwise_left_shift(1) is -2i16. Bit indexes must be 0..15 (Integer16) or 0..31 (Integer32), and abs raises for the minimum value, which has no positive counterpart.
let port: Integer16 := 8080i16
print(port.to_string(16)) -- "1f90"
print(port.bitwise_left_shift(4)) -- -1792 (129280 wrapped to 16 bits)
print((port + 1).to_integer16()) -- 8081
Array[T]Construction:
[]
Main methods:
| Method | Purpose |
|---|---|
get(index) |
Read element at index. |
add(value) |
Append value. |
add_at(index, value) |
Insert value. |
put(index, value) |
Replace value at index. |
length |
Element count. |
is_empty |
Check emptiness. |
contains(elem) |
Membership test. |
index_of(elem) |
First index or -1. |
remove(index) |
Remove element at index. |
reverse |
Return reversed array. |
sort |
Sort array. |
slice(start, end) |
Subrange. |
concat(other) |
Return a new array with other appended. |
cursor |
Iterator for across. |
Map[K, V]Construction:
{}
Main methods:
| Method | Purpose |
|---|---|
get(key) |
Read value for key. |
try_get(key, default) |
Read value or fallback. |
set(key, value) |
Add or replace an entry. |
put(key, value) |
Alias for set. |
size |
Number of entries. |
is_empty |
Check emptiness. |
contains_key(key) |
Membership by key. |
keys |
Array of keys. |
values |
Array of values. |
remove(key) |
Delete entry. |
cursor |
Iterator over entries. |
Set[T]Construction:
create Set[Integer].from_array([1, 2, 3])
#{}
#{1, 2, 3}
Notes:
#{1, 2, 3} create sets.#{}.{} still creates an empty map.Main methods:
| Method | Purpose |
|---|---|
contains(value) |
Membership test. |
union(other) |
Set union. |
difference(other) |
Elements in this set but not in other. |
intersection(other) |
Common elements. |
symmetric_difference(other) |
Elements that occur in exactly one set. |
size |
Number of elements. |
is_empty |
Check emptiness. |
cursor |
Iterator for across. |
Stack[T]Stack[T] is not a built-in collection type. It is the standard tutorial example of a user-defined generic collection class built on top of Array[T].
Typical operations:
| Method | Purpose |
|---|---|
push(value) |
Add an element to the top. |
pop() |
Remove and return the top element. |
peek() |
Return the top element without removing it. |
is_empty() |
Check emptiness. |
size() |
Number of stored elements. |
Arrays, sets, maps and strings share eight methods that take a function. Each visits the elements in across order: a string’s Chars, a map’s Map_Entry values.
| Method | Returns |
|---|---|
map(f) | an Array of what f returns |
filter(f) | the elements f accepts, as the receiver’s own type |
fold(init, f) | the elements combined with f, starting from init |
reduce(f) | the same, starting from the first element (raises when empty) |
any(f), all(f) | Boolean |
count(f) | how many elements f accepts |
find(f) | the first element f accepts, or nil |
Concrete cursor classes:
ArrayCursorStringCursorMapCursorSetCursorEach is a Cursor[T] for its collection’s element type (an Array[Integer]’s cursor is a Cursor[Integer]), and they are usually used indirectly through across.
ConsolePredeclared as console in every program and REPL session. Construction, when you need your own:
create Console
Main methods:
printprint_lineread_lineerrornew_lineflushread_integerread_realProcessConstruction:
create Process
Main methods:
getenvsetenvcommand_lineProgramPredeclared as program: the running program. Construction (takes no constructor or arguments):
create Program
Main methods:
argumentsenvhas_envworking_directorypidexitTask[T]Construction:
let t: Task[Integer] := spawn do
result := 42
end
Main methods:
awaitawait(ms)cancelis_doneis_cancelledChannel[T]Construction:
create Channel[Integer]
create Channel[Integer].with_capacity(2)
Main methods:
sendsend(value, ms)try_sendreceivereceive(ms)try_receivecloseis_closedcapacitysizeComparable.length; map and set element counts use size.Task and Channel are built-in concurrency abstractions available directly in Nex programs.For the fuller per-type reference, see the Nex Reference.