Unlike
ArkTS, Cangjie is not derived from any existing programming languages. The programming language, however, employs modern programming-language theory concepts and advanced features found in other existing languages in its category, such as
Java. It can be used in a multi-language hybrid development environment, with the
Typescript-centric ArkTS language, to create complementary advantages for greater efficiency gains and based on different scenarios. Cangjie features an embedded AgentDSL programming framework, natural language & programming language organic integration. It is reported that applications that have already been developed on existing
ArkTS do not need to be redeveloped into the Cangjie version on HarmonyOS Next version. HarmonyOS supports high-performance
interoperability between the Cangjie language and the ArkTS language. In the future, developers can choose between the Cangjie programming language or ArkTS for incremental development to satisfy developer needs. Cangjie also supports various
toolchains for app development, including language services such as: highlighting and association,
debugging with cross-language debugging and thread-level visual debugging, static checking, performance analysis, package management, document generation, Mock tools, testing frameworks, coverage tools, Fuzz tools, and intelligent assisted programming tools.
Basic syntax Cangjie's
"Hello, World!" program is: main() { println("Hello, World!") }
Immutable variables are declared with the keyword and mutable ones with the {{code|var
Pattern matching Pattern matching in Cangjie is provided by the match expression, which has two forms: one with a value to match and the other without a value to match. A match expression with a value checks each case in sequence, executing the corresponding code when the pattern matches successfully. To ensure exhaustiveness, the last case often uses a
wildcard pattern _ to cover all possible values. A match expression without a value will still evaluate the expression following the case and does not need a pair of brackets for the condition.
Lambda expression A
lambda expression can have no parameters: let f = {a: Int64, b: Int64 => a + b} let print = { => println("Hello Cangjie")}
Foreign function interface Cangjie has built-in
FFI support for
C and
Python. External functions are declared using the foreign keyword and called using the unsafe keyword. For C interoperability, Cangjie supports automatic conversion between basic data types. The CPointer type corresponds to C pointer types, for example, and CPointer corresponds to int32_t *. For Python, Cangjie supports interaction through the ffi.python library in std. It requires Python version 3.0 or above and currently only works on Linux. Below is an example:
Metaprogramming Cangjie is explicitly designed for meta-programming and supports two main types of
macros: • Non-attribute macros, which take a single input parameter for the code being decorated. • Attribute macros, which accept an additional attribute parameter allowing developers to pass extra information to the macro. Compared to functions, macros in Cangjie require the keyword, that can be placed in a and are invoked using the @ symbol. While macro nesting is supported in calls, macro definitions cannot be nested themselves. The expansion of nested macros follows an inside-out order, and macros can share information through global variables. Macros can appear in both parenthesized and non-parenthesized calls. Developers can use quote expressions to create Token objects. == STD module runtime ==