Cangjie Programming Language Standard Library Overview
The Cangjie Programming Language Standard Library (std) is a default library included with the Cangjie SDK installation. The standard library predefines a set of functions, classes, structures, etc., designed to provide commonly used functionalities and utilities, enabling developers to write programs more quickly and efficiently.
The Cangjie Standard Library has three key characteristics and objectives:
- Ease of Use: The standard library is distributed with the compiler and toolchain, requiring no additional downloads—ready to use out of the box.
- General Functionality: The standard library offers the most frequently used library capabilities, aiming to solve most fundamental problems for developers.
- Quality Benchmark: The standard library strives to set examples and benchmarks in performance, coding style, and other aspects for other Cangjie libraries.
Usage Guide
In the Cangjie programming language, the standard library consists of several packages, where a package is the smallest compilation unit. Each package can independently produce outputs such as AST (Abstract Syntax Trees) files, static library files, dynamic library files, etc. Packages can define sub-packages, forming a tree-like structure. A package without a parent is called a root package, and the entire tree formed by the root package and its sub-packages (including sub-packages of sub-packages) is called a module. The module's name is the same as the root package and represents the smallest unit for developer releases.
Package import rules are as follows:
-
You can import a top-level declaration or definition from a package using the following syntax:
import fullPackageName.itemNameHere,
fullPackageNameis the complete path of the package name, anditemNameis the name of the declaration. For example:import std.collection.ArrayList -
If multiple
itemNames belong to the samefullPackageName, you can use:import fullPackageName.{itemName[, itemName]*}For example:
import std.collection.{ArrayList, HashMap} -
You can also import all top-level declarations or definitions marked as
publicfrom thefullPackageNamepackage using:import fullPackageName.*For example:
import std.collection.*
Package List
The std library includes several packages that provide rich foundational functionalities:
| Package Name | Functionality |
|---|---|
| core | The core package of the standard library, providing the most fundamental API capabilities for Cangjie programming. |
| argopt | The argopt package provides capabilities for parsing parameter names and values from command-line argument strings. |
| ast | The ast package mainly includes Cangjie source code syntax parsers and Cangjie syntax tree nodes, offering syntax parsing functions. |
| binary | The binary package provides interfaces for converting between basic data types and binary byte arrays with different endianness, as well as endianness reversal. |
| collection | The collection package offers efficient implementations of common data structures, definitions of related abstract interfaces, and frequently used functions in collection types. |
| collection.concurrent | The collection.concurrent package provides thread-safe implementations of collection types. |
| console | The console package provides methods for interacting with standard input, output, and error streams. |
| convert | The convert package offers Convert series functions for converting strings to specific types, as well as formatting capabilities, primarily for converting Cangjie type instances to formatted strings. |
| crypto.cipher | The crypto.cipher package provides generic interfaces for symmetric encryption and decryption. |
| crypto.digest | The crypto.digest package offers generic interfaces for common digest algorithms, including MD5, SHA1, SHA224, SHA256, SHA384, SHA512, HMAC, and SM3. |
| database.sql | The database.sql package provides interfaces for Cangjie to access databases. |
| deriving | The deriving package provides a set of macros for automatically generating interface implementations. |
| env | The env package offers information and functionalities related to the current process, including environment variables, command-line arguments, standard streams, and program termination. |
| fs | The fs (file system) package provides functions for operating on files, directories, paths, and file metadata. |
| io | The io package enables data exchange between programs and external devices. |
| math | The math package provides common mathematical operations, constant definitions, floating-point number handling, and other functionalities. |
| math.numeric | The math.numeric package extends capabilities beyond the expressible range of basic types. |
| net | The net package provides common network communication functionalities. |
| objectpool | The objectpool package offers capabilities for object caching and reuse. |
| overflow | The overflow package provides functionalities related to overflow handling. |
| posix | The posix package encapsulates POSIX system calls, offering cross-platform system operation interfaces. |
| process | The process package mainly provides Process operation interfaces, including process creation, standard stream acquisition, process waiting, and process information querying. |
| random | The random package provides capabilities for generating pseudo-random numbers. |
| reflect | The reflect package offers reflection functionalities, enabling programs to obtain type information of various instances at runtime and perform read/write and invocation operations. |
| regex | The regex package provides capabilities for analyzing and processing text using regular expressions (supporting UTF-8 encoded Unicode strings), including search, split, replace, and validation functionalities. |
| runtime | The runtime package interacts with the program's runtime environment, providing a series of functions and variables for controlling, managing, and monitoring program execution. |
| sort | The sort package provides sorting functions for array types. |
| sync | The sync package offers capabilities related to concurrent programming. |
| time | The time package provides time-related types, including date-time, time intervals, monotonic time, and time zones, along with functionalities for calculation and comparison. |
| unicode | The unicode package provides capabilities for handling characters according to the Unicode encoding standard. |
| unittest | The unittest package is used for writing unit test code for Cangjie projects, providing basic functionalities including code writing, execution, and debugging. |
| unittest.mock | The unittest.mock package provides a mock framework for Cangjie unit tests, offering APIs to create and configure mock objects that have API signatures consistent with real objects. |
| unittest.testmacro | The unittest.testmacro package provides macros required by users for the unit testing framework. |
| unittest.mock.mockmacro | The unittest.mock.mockmacro package provides macros required by users for the mock framework. |
| unittest.common | The unittest.common package provides types and general methods required for printing in the unit testing framework. |
| unittest.diff | The unittest.diff package provides APIs required for printing difference comparison information in the unit testing framework. |
| unittest.prop_test | The unittest.prop_test package provides types and general methods required for parameterized testing in the unit testing framework. |