Content deleted Content added
lambda |
|||
(5 intermediate revisions by 2 users not shown) | |||
Line 1:
{{AFC submission|d|nn|u=158.181.216.135|ns=118|decliner=Stuartyeates|declinets=20250102225902|ts=20241128073832}} <!-- Do not remove this line! -->
{{AFC comment|1=The article needs independent coverage, that is secondary source with in depth coverage not written or published by people associated with the language. Pretty much all of the sources below are good for sourcing details of the language but not for proving notability. [[User:Stuartyeates|Stuartyeates]] ([[User talk:Stuartyeates|talk]]) 22:59, 2 January 2025 (UTC)}}
----
{{Short description|Programming language}}
{{Draft topics|internet-culture|software|computing|technology}}
{{AfC topic|stem}}
{{Connected contributor|Poppodoms}}
{{COI|date=July 2024}}
Line 34 ⟶ 39:
}}
'''Cangjie''' is a [[High-level programming language|high-level]], [[static typing|statically typed]], [[general-purpose programming language|general-purpose]], [[multi-paradigm programming language|multi-paradigm]], [[compiled language|compiled]] [[Imperative programming|imperative]] and [[Declarative programming|declarative]] [[programming language]] developed by [[Huawei]] which was first released on June 21, 2024, as a beta recruitment of the developer preview version of the [[HarmonyOS NEXT]] app development for [[HarmonyOS]] operating system.<ref name="vid" /> It is also referred to as '''CangjieLang''' or '''CJ''' but its proper name is Cangjie.<ref>{{Cite web |last=Matsui |first=Emiko |date=2024-06-21 |title=Huawei programming language to make official debut at HDC 2024 |url=https://www.huaweicentral.com/huawei-programming-language-to-make-official-debut-at-hdc-2024/ |access-date=2024-07-06 |website=Huawei Central |language=en-US}}</ref>
== History ==
Line 44 ⟶ 49:
During HDC 2021, in October 2021, HarmonyOS 3 Developer Preview was officially released as the OS was moving towards [[Declarative programming|declarative]] programming software development. Huawei also announced that at that time that it would introduce the self-developed programming language for HarmonyOS in the future.<ref>{{Cite web |last=Benjie |first=Joshua |date=2022-03-17 |title=Huawei testing own programming language registration |url=https://www.rprna.com/news/huawei-testing-own-programming-language-registration/ |access-date=2024-07-06 |website=RPRNA |language=en-US}}</ref>
It has also been reported between 2021 and 2022 that Huawei's programming language originally supposed to launch in 2022 or sometime around second half of 2022 which was pushed back due to ongoing development of HarmonyOS operating system internally.<ref name="vid" /><ref>{{Cite web |last=Li |first=Deng |date=2022-06-16 |title=Huawei's programing language will launch in the second half of this year |url=https://www.huaweicentral.com/huaweis-programing-language-will-launch-in-the-second-half-of-this-year/ |access-date=2024-07-06 |website=Huawei Central |language=en-US}}</ref><ref>{{Cite web |last=Walker |first=Elyssa |date=2020-02-02 |title=Huawei is developing its own programming language - it will be presented in 2022 |url=https://www.codebugapp.com/building/huawei-is-developing-its-own-programming-language-it-will-be-presented-in-2022/ |access-date=2024-07-06 |website=CodeBug'22 |language=en-US}}</ref>
On May 17, 2024, Cangjie programming language was internally added into OpenHarmony source code through its [[Foreign function interface|foreign function interface (FFI)]] mechanism.<ref>{{Cite web |last=Benjamin |date=2024-05-14 |title=Huawei's self developed programming language Cangjie (CJ) could be coming later this month closer than expected |url=https://harmonyoshub.com/huaweis-self-developed-programming-language-cangjie-cj-could-be-coming-later-this-month-closer-than-expected/ |access-date=2024-07-06 |website=HarmonyOSHub |language=en-GB}}</ref>
Line 75 ⟶ 80:
The platforms Cangjie supports are [[HarmonyOS]], [[Linux]], [[Windows]] and [[macOS]] for app development.
A key aspect of Cangjie design is its ability to attach with or without ArkTS code developed for HarmonyOS development. On Huawei devices running HarmonyOS, it allows Native APIs in DevEco Studio templates alternative to traditional Native APIs of [[C (programming language)|C]], [[C++]] alongside ArkTS code to run within one program.<ref>{{Cite web |title= |script-title=zh: 华为仓颉编程语言首批合作企业亮相:中国工商银行、中国移动、科蓝软件等在列 |trans-title=Huawei's
== Features ==
Line 81 ⟶ 86:
Unlink [[ArkTS]], Cangjie is a general purpose programming language that is not based on any existing programming languages. The programming language employs modern programming-language theory concepts of other existing programming languages of its category that influences it such as [[Java (programming language)|Java]] with simple and advanced syntax features like [[TypeScript|Typescript]]-centric ArkTS language, in declarative programming development by complementing it with efficiency.<ref>{{Cite web |title=华为:仓颉编程语言自主可控,没有基于任何现有的编程语言演进 - IT之家 |url=https://www.ithome.com/0/776/781.htm |access-date=2024-07-06 |website=www.ithome.com}}</ref>
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 Cangjie programming language or ArkTS for incremental development for developer needs.<ref>{{Cite web |date=2024-06-21 |title=Huawei has announced its own programming language Cangjie |url=https://itc.ua/en/news/huawei-has-announced-its-own-programming-language-cangjie/ |access-date=2024-07-06 |website=ITC.ua}}</ref><ref>{{Cite web |title=华为开启鸿蒙 HarmonyOS NEXT 仓颉编程语言开发者预览版 Beta 招募 - IT之家 |url=https://www.ithome.com/0/776/773.htm |access-date=2024-07-06 |website=www.ithome.com}}</ref>
Line 98 ⟶ 103:
|swift}} keyword. Values must be initialized before they are read. Values may infer their type based on the type of the provided initial value. If the initial value is set after the value's declaration, a type must be declared explicitly.<ref>{{cite book |last1=劉玥 |title=Cangjie Programming Quick Start |date=2024-07-01 |isbn=9787115624710 |script-title=zh:仓颉编程快速上手}}</ref>
=== Pattern matching ===
Lambda expression can have no parameters:<ref>{{Cite book |title= |publisher=[[Tsinghua University Press]] |year=2024 |isbn=9787302616597 |script-title=zh:仓颉语言实战(微课视频版) |trans-title=Hands on Cangjie Language (Video Course Version)}}</ref><syntaxhighlight lang="swift" line="1" start="1">▼
[[Pattern matching]] in Cangjie is provided by the <code>match</code> expression, which has two forms: one with a value to match and the other without a value to match. A <code>match</code> expression with a value checks each <code>case</code> in sequence, executing the corresponding code when the pattern matches successfully. To ensure exhaustiveness, the last <code>case</code> often uses a [[Wildcard character|wildcard]] pattern <code>_</code> to cover all possible values. A <code>match</code> expression without a value evaluates does not need a pair of brackets for the condition.<ref name="vid" />
=== Lambda expression ===
▲Lambda expression can have no parameters:<ref name="vid">{{Cite book |last=张磊 |title= |publisher=[[Tsinghua University Press]] |year=2024 |isbn=9787302616597 |script-title=zh:仓颉语言实战(微课视频版) |trans-title=Hands on Cangjie Language (Video Course Version)}}</ref><syntaxhighlight lang="swift" line="1" start="1">
let f = {a: Int64, b: Int64 => a + b}
let print = { => println("Hello Cangjie")}
</syntaxhighlight>
=== Foreign function interface ===
Cangjie has built-in [[Foreign function interface|FFI]] support for [[C (programming language)|C]] and [[Python (programming language)|Python]]. External functions are declared using the <code>foreign</code> keyword and called using the <code>unsafe</code> keyword. For C interoperability, Cangjie supports automatic conversion between basic data types. The <code>CPointer<T></code> type corresponds to C pointer types, for example, and <code>CPointer<Int32></code> corresponds to <code>int32_t *</code>. 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.<ref name=":0">{{Cite book |last=徐礼文 |title= |publisher=[[Tsinghua University Press]] |isbn=9787302625889 |script-title=zh:仓颉语言核心编程——入门、进阶与实战 |trans-title=Cangjie Language Core Programming: Introduction, Advanced Topics and Practical Applications}}</ref> Below is an example:
{|
!C code
!Cangjie code
|-
|<syntaxhighlight lang="c" line="1">
#include <stdio.h>
#include <stdlib.h>
int getRandom() {
int i = rand();
return i;
}
</syntaxhighlight>
|<syntaxhighlight lang="swift" line="1">
from std import ffi.c.*
foreign func getRandom(): Int32
main(): Unit {
let r = unsafe getRandom()
println("random number $(r)")
}
</syntaxhighlight>
|}
=== Metaprogramming ===
Cangjie supports two main types of macros: non-attribute macros, which take a single input parameter for the code being decorated, and 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 {{code|macro|}} keyword, placed in {{code|macro package|}}, and being 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.<ref name=":0" />
== STD module runtime ==
{{See also|Ark Compiler}}
STD module runtime, known as Std.runtime is a module runtime package for Cangjie Standard Library via Cangjie Programming Language Library API that interacts with the program's runtime environment, with varaibles of controlling, managing and monitoring the program's execution.<ref name="vid" />
== Development tools ==
=== Compiler ===
With [[Ark Compiler]], it supports a variety of dynamic and static programming languages such as [[JavaScript|JS]], [[TypeScript|TS]], and ArkTS as well as Cangjie. It is the compilation and runtime base that enables OpenHarmony alongside HarmonyOS based on the same platform to run on multiple device forms such as smart devices, mobile phones, PCs, tablets, TVs, automobiles, and wearables. ArkCompiler consists of two parts, compiler toolchain and runtime.<ref>{{cite web |title=ArkCompiler Runtime |url=https://gitee.com/openharmony/docs/blob/master/en/readme/ARK-Runtime-Subsystem.md |website=OpenAtom Gitee |access-date=12 February 2024}}</ref>
=== Package manager ===
Cangjie Package Manager ('''CPM''') is the built-in package management tool for the Cangjie programming language that comes installed with the cjc toolchain. In Cangjie, a package is the smallest compilation unit, with each package capable of containing multiple source files (.cj files) and having its own namespace; a module is a collection of packages, representing a complete functional unit and serving as the minimum unit for third-party developer releases. <samp>new</samp> command creates a new module, generating a module.json file and src folder. Each module's program entry point must be in its root directory, and the top level can have at most one main function as the program entry point.<ref name=":0" />
=== IDE and editor support ===
Line 133 ⟶ 176:
{{Draft categories|
[[:Category:2024 software]]
[[:Category:Cross-platform software]]
[[:Category:Object-based programming languages]]
[[:Category:Scripting languages]]
[[:Category:Source-to-source compilers]]
[[:Category:Statically typed programming languages]]
[[:Category:Huawei products]]
}}
|