len :: proc(v: Type) -> int
The len
built-in procedure return the length of v
, according to its type:
Array: the number of elements in v Pointer to array: the number of elements in v^ (even if v is nil) Slice: the number of elements in v; if v in nil, len(v) is zero Dynamic array: the number of elements in v; if v in nil, len(v) is zero Map: the number of elements in v; if v in nil, len(v) is zero String: the number of bytes in v
If the parameter passed is an enumeration type, it will return the number of enumeration values:
Foo :: enum {A, B, C}; #assert(len(Foo) == 3);
cap :: proc(v: Type) -> int
The cap
built-in procedure return the capacity of v
, according to its type:
Dynamic array: the maximum length the dynamic array can reach before it requires a resize; if v in nil, len(v) is zero
complex :: proc(r, i: Float_Type) -> Complex_Type `` The `complex` built-in procedure constructs a complex value from two floating-point values. The floating point values must be of the same type and the return value will be the corresponding complex type:
f32 -> complex64 f64 -> complex128
## real
real :: proc(c: ComplexType) -> FloatType
`
The
realbuilt-in procedure returns the real component of the complex number
c. The return value will be a floating point that corresponds to the type of
c`:
complex64 -> f32 complex128 -> f64
imag :: proc(c: Complex_Type) -> Float_Type `` The `imag` built-in procedure returns the imaginary component of the complex number `c`. The return value will be a floating point that corresponds to the type of `c`:
complex64 -> f32 complex128 -> f64
## conj
conj :: proc(c: ComplexType) -> ComplexType
`
The
conjbuilt-in procedure complex conjugate of the value
c`.
conj(a + i*b) == a - i*b
copy :: proc(dst, src: $T/[]$E) -> int
The copy
built-in procedure copies the elements from a source slice to a destination slice. The source and destination are allowed to overlap. copy
returns the number of elements that were copied, which is equal to min(len(dst), len(src))
.
new :: proc(T: type) -> ^T
The new
built-in procedure allocates memory, from the current context's allocator. The first argument is a type, not a value, and the value returned is a pointer to an allocated zero value of that type.
new_clone :: proc(v: $T) -> ^T
The new_clone
built-in procedure allocates memory, from the current context's allocator. The first argument is a value, not a type, and the value returned is a pointer to an allocated clone of that value passed.
make :: proc(T: type, parameters ..Integer_Type) -> T
The make
built-in procedure allocates and initializes an object an of type slice, dynamic array, and map. Like new
, the first argument is a type, not a value. Unlike new
, make
's return type is the same as the type of its argument, not a pointer to it.
incl :: proc(s: ^$S/bit_set[$T, $U], elems: ..$T) -> S
The incl
built-in procedure includes elements into a bit set and then returns the original passed bit set. The procedure is equivalent to the following code:
for elem in elems { s^ |= {elem}; }
incl :: proc(s: ^$S/bit_set[$T, $U], elems: ..$T) -> S
The incl
built-in procedure excludes elements into a bit set and then returns the original passed bit set. The procedure is equivalent to the following code:
for elem in elems { s^ &~= {elem}; }