std.core

Function Description

The core package provides some basic API capabilities applicable to Cangjie programming.

Built-in types (such as signed integer, unsigned integer, and floating-point number), common functions (such as print, println, and eprint), common interfaces (such as ToString, Hashable, Equatable, and Collection), common classes and structs (such as Array, String, and Range), and common exception classes (such as Error, Exception, and their subclasses) are provided.

NOTE

The core package is imported by default.

API List

Function

NameDescription
acquireArrayRawData(Array<T>) where T <: CTypeObtains an original pointer instance of data in Array, where T must meet the CType constraint.
alignOf<T>() where T <: CTypeObtains the memory alignment value of T type.
eprint(String, Bool)Prints the specified string to the standard error text stream.
eprintln(String)Prints the specified string (with a newline character at the end) to the standard error text stream.
eprint<T>(T, Bool) where T <: ToStringPrints the string representation of a specified instance of the T type to the standard error text stream.
eprintln<T>(T) where T <: ToStringPrints the string representation (with a newline character at the end) of a specified instance of the T type to the standard error text stream.
ifNone(Option<T>, () -> Unit)If data of the Option.None type is input, the action function is executed.
ifSome(Option<T>, (T) -> Unit)If data of the Option.Some type is input, the action function is executed.
max<T>(T, T, Array<T>) where T <: Comparable<T>Obtains the maximum value in a data set.
min<T>(T, T, Array<T>) where T <: Comparable<T>Obtains the minimum value in a data set.
print(Bool, Bool)Outputs the string representation of data of the Bool type to the console.
print(Float16, Bool)Outputs the string representation of data of the Float16 type to the console.
print(Float32, Bool)Outputs the string representation of data of the Float32 type to the console.
print(Float64, Bool)Outputs the string representation of data of the Float64 type to the console.
print(Int16, Bool)Outputs the string representation of data of the Int16 type to the console.
print(Int32, Bool)Outputs the string representation of data of the Int32 type to the console.
print(Int64, Bool)Outputs the string representation of data of the Int64 type to the console.
print(Int8, Bool)Outputs the string representation of data of the Int8 type to the console.
print(Rune, Bool)Outputs the string representation of data of the Rune type to the console.
print(String, Bool)Outputs a specified string to the console.
print(UInt16, Bool)Outputs the string representation of data of the UInt16 type to the console.
print(UInt32, Bool)Outputs the string representation of data of the UInt32 type to the console.
print(UInt64, Bool)Outputs the string representation of data of the UInt64 type to the console.
print(UInt8, Bool)Outputs the string representation of data of the UInt8 type to the console.
print<T>(T, Bool) where T <: ToStringOutputs the string representation of an instance of the T type to the console.
println()Outputs a newline character to the standard output (stdout).
println(Bool)Outputs the string representation (with a newline character at the end) of data of the Bool type to the console.
println(Float16)Outputs the string representation (with a newline character at the end) of data of the Float16 type to the console.
println(Float32)Outputs the string representation (with a newline character at the end) of data of the Float32 type to the console.
println(Float64)Outputs the string representation (with a newline character at the end) of data of the Float64 type to the console.
println(Int16)Outputs the string representation (with a newline character at the end) of data of the Int16 type to the console.
println(Int32)Outputs the string representation (with a newline character at the end) of data of the Int32 type to the console.
println(Int64)Outputs the string representation (with a newline character at the end) of data of the Int64 type to the console.
println(Int8)Outputs the string representation (with a newline character at the end) of data of the Int8 type to the console.
println(Rune)Outputs the string representation (with a newline character at the end) of data of the Rune type to the console.
println(String)Outputs a specified string (with a newline character at the end) to the console.
println(UInt16)Outputs the string representation (with a newline character at the end) of data of the UInt16 type to the console.
println(UInt32)Outputs the string representation (with a newline character at the end) of data of the UInt32 type to the console.
println(UInt64)Outputs the string representation (with a newline character at the end) of data of the UInt64 type to the console.
println(UInt8)Outputs the string representation (with a newline character at the end) of data of the UInt8 type to the console.
println<T>(T) where T <: ToStringOutputs the string representation (with a newline character at the end) of instance of the T type to the console.
readln()Receives the console input until the newline or end of file (EOF).
refEq(Object, Object)Checks whether the memory addresses of two Object instances are the same.
releaseArrayRawData(CPointerHandle<T>) where T <: CTypeReleases an original pointer instance obtained using acquireArrayRawData.
sizeOf<T>() where T <: CTypeObtains the memory space occupied by the T type.
sleep(Duration)Hibernates the current thread.
zeroValue<T>()Obtains a T-type instance that has been subject to zero initialization.

Type Alias

NameDescription
ByteThe Byte type is the alias of the built-in UInt8 type.
IntThe Int type is the alias of the built-in Int64 type.
UIntThe UInt type is the alias of the built-in UInt64 type.

Built-in Type

NameDescription
Int8Represents an 8-bit signed integer ranging from –2^7 to 2^7 – 1.
Int16Represents a 16-bit signed integer ranging from –2^{15} to 2^{15} – 1.
Int32Represents a 32-bit signed integer ranging from –2^{31} to 2^{31} – 1.
Int64Represents a 64-bit signed integer ranging from –2^{63} to 2^{63} – 1.
IntNativeRepresents a platform-related signed integer with the length same as the bit width of the current system.
UInt8Represents an 8-bit unsigned integer ranging from 0 to 2^8-1.
UInt16Represents a 16-bit unsigned integer ranging from 0 to 2^{16}-1.
UInt32Represents a 32-bit unsigned integer ranging from 0 to 2^{32}-1.
UInt64Represents a 64-bit unsigned integer ranging from 0 to 2^{64}-1.
UIntNativeRepresents a platform-related unsigned integer with the length same as the bit width of the current system.
Float16Represents a 16-bit floating-point number complying with the half-precision format (binary16) specified in IEEE 754.
Float32Represents a 32-bit floating-point number complying with the single-precision format (binary32) specified in IEEE 754.
Float64Represents a 64-bit floating-point number complying with the double-precision format (binary64) specified in IEEE 754.
BoolRepresents the Boolean type. The value options are true and false.
RuneRepresents the characters in the Unicode character set.
UnitRepresents the type of an expression that concerns only side effects but not values in the Cangjie language.
CPointer<T>Indicates the pointer to the instance of the T type. It corresponds to T* of the C language in the scenario where the C language is used.
CStringRepresents the C-style string, which is used in the scenario where the C language is used.

Interface

NameDescription
AnySpecifies the parent type of all types. By default, all interface types inherit Any and all non-interface types implement Any.
HasherProcesses combined hash operations.
ThreadContextSpecifies a Cangjie thread context interface.
Countable<T>Indicates a countable type.
Collection<T>Indicates a collection. Generally, a container type should implement this interface.
Less<T>Supports calculations with the result indicating whether one instance is less than the other instance or not.
Greater<T>Supports calculations with the result indicating whether one instance is greater than the other instance or not.
LessOrEqual<T>Supports calculations with the result indicating whether one instance is less than or equal to the other instance or not.
GreaterOrEqual<T>Supports calculations with the result indicating whether one instance is greater than or equal to the other instance or not.
Comparable<T>Indicates comparison operation. This interface is a collection of interfaces indicating equal to, less than, greater than, less than or equal to, and greater than or equal to.
Equal<T>Supports equality check.
NotEqual<T>Supports inequality check.
Equatable<T>Specifies a collection of the equality check and inequality check interfaces.
HashableCalculates hash values.
Iterable<E>Supports iteration. A type (usually the container type) that implements this interface can be iterated in the for-in statement. Alternatively, such type can be iterated by calling the next function based on the corresponding iterator type instance.
ResourceManages resources, such as closing and releasing memory and handles.
ToStringProvides the string representation of a specific type.
CTypeIndicates the interface that supports interoperability with the C language.

Class

NameDescription
ArrayIterator<T>Specifies an array iterator. For details about its functions, see the description of Iterable and Iterator.
Box<T>Provides the capability of adding a layer of class encapsulation to other types.
Future<T>Represents a Cangjie thread task. It can be used to obtain the calculation result of a Cangjie thread and send a cancellation signal to the Cangjie thread.
Iterator<T>Indicates an iterator and provides the next method to support iterative traversal of members in a container.
ObjectConstructs an object instance.
RangeIterator<T> <: Iterator<T> where T <: Countable<T> & Comparable<T> & Equatable<T>Specifies an iterator of the Range type. For details about its functions, see the description of Iterable and Iterator.
StackTraceElementIndicates the detailed information about an exception stack, including the class name, function name, file name, and line number involved in the exception.
StringBuilderConstructs strings.
ThreadRepresents a Cangjie class, which can be used to obtain thread IDs and names, check whether a thread receives any cancellation request, and register processing functions for exceptions not handled by threads.
ThreadLocal<T>Indicates a Cangjie thread local variable.

Enumeration

NameDescription
AnnotationKindIndicates the location that the custom annotation is expected to support.
EndianIndicates the endianness of the running platform, which can be big endian or little endian.
OrderingIndicates a comparison result and includes three situations: less than, greater than, and equal to.
Option<T>Encapsulates the T type, indicating that the type may or may not have a value.

Struct

NameDescription
Array<T>Specifies a Cangjie array type used to represent an ordered sequence consisting of elements of a single type.
CPointerHandle<T> where T <: CTypeIndicates the original pointer of Array. Generic parameters in this type must meet the CType constraint.
CPointerResource<T> where T <: CTypeIndicates the resource management type corresponding to CPointer. Instances of this type can be obtained by using the member function asResource of CPointer.
CStringResourceIndicates the resource management type corresponding to CString. Instances of this type can be obtained by using the member function asResource of CString.
DefaultHasherProvides the default hash algorithm implementation.
DurationIndicates an interval of the time type, which provides common static instances and the calculation and comparison functionalities.
LibCProvides C APIs that are frequently used in Cangjie, such as APIs for applying for and releasing CType instances on the heap.
Range<T> where T <: Countable<T> & Comparable<T> & Equatable<T>Indicates an interval type used to indicate a sequence of T with a fixed range and step. T must be countable and ordered.
StringIndicates a Cangjie string with a series of string operations provided, such as construction, search, and concatenation.

Exception Class

NameDescription
ArithmeticExceptionIndicates the arithmetic exception class which is thrown when an arithmetic exception occurs.
ErrorSpecifies the parent class of all error classes. This class cannot be inherited or initialized, but can be captured.
ExceptionSpecifies the parent class of all exception classes.
IllegalArgumentExceptionIndicates the exception class that is thrown when a parameter is invalid.
IllegalFormatExceptionIndicates the exception class that is thrown when the format of a variable is invalid or not standard.
IllegalMemoryExceptionIndicates the exception class that is thrown when a memory operation error occurs.
IllegalStateExceptionIndicates the exception class that is thrown when a status is invalid.
IncompatiblePackageExceptionIndicates the exception class that is thrown when the package is incompatible.
IndexOutOfBoundsExceptionIndicates the exception class that is thrown when an index is out of range.
InternalErrorIndicates the internal error class. This class cannot be initialized but can be captured.
NegativeArraySizeExceptionIndicates the exception class that is thrown when the array size is negative.
NoneValueExceptionIndicates the exception class that is thrown (usually in the getOrThrow function) when the value of the Option<T> instance is None.
OutOfMemoryErrorIndicates the out-of-memory error class. This class cannot be inherited or initialized, but can be captured.
OverflowExceptionIndicates the exception class this is thrown when overflow occurs in an arithmetic operation.
SpawnExceptionIndicates the thread exception class, indicating that an exception occurs during thread processing.
StackOverflowErrorIndicates the stack overflow error class. This class cannot be inherited or initialized, but can be captured.
TimeoutExceptionIndicates an exception that is thrown when the blocking operation times out.
UnsupportedExceptionIndicates the exception class that is thrown when a functionality is not supported.