Draft:Cangjie (programming language): Difference between revisions

Content deleted Content added
Platforms: Add a translated title for a citation
 
(3 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}}
 
{{AfC submission|||ts=20241128073832|u=158.181.216.135|ns=118}}
{{AfC submission|t||ts=20240712213913|u=Poppodoms|ns=118|demo=}}
{{Connected contributor|Poppodoms}}
{{COI|date=July 2024}}
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.
Cangjie features an embedded AgentDSL programming framework, natural language & programming language organic integration. Its lightweight threads provide better concurrency and lower overhead compared to Kotlin and Java on Android, as shown in benchmark tests. <ref>{{Cite AV media |url=https://www.youtube.com/watch?v=odSh9kSfhas |title=Cangjie language compared with Java and Kotlin language on app scrolling |date=2024-06-23 |last=Living In Harmony |access-date=2024-07-06 |via=YouTube}}</ref><ref>{{Cite web |title=华为自研仓颉编程语言官网和开发文档上线,首次融入鸿蒙生态 - IT之家 |url=https://www.ithome.com/0/776/758.htm |access-date=2024-07-06 |website=www.ithome.com}}</ref>
 
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 name="vid">{{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 ==
Line 110 ⟶ 150:
=== 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]]
}}