Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion skills/basic_data_type/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,21 @@ description: "仓颉语言基本数据类型。当需要了解仓颉语言的整
### 5.4 支持的运算
- 关系运算符用于比较
- `+` 用于拼接
- `*` 用于重复:`"ab" * 3` → `"ababab"`

### 5.5 字符串迭代
### 5.5 常用方法
- `s.size` — UTF-8 字节长度(非字符数)
- `s.isEmpty()` — 是否为空串
- `s.contains(sub)` — 是否包含子串
- `s.split(sep)` — 按分隔符分割,返回 `Array<String>`
- `s.replace(old, new)` — 替换所有匹配子串
- `s.trimAscii()` — 裁剪两端 ASCII 空白
- `s.startsWith(prefix)` / `s.endsWith(suffix)` — 前缀/后缀检查
- `s.indexOf(sub)` — 查找子串位置,返回 `?Int64`

> 完整 String API 请参阅 `cangjie-std-string` Skill

### 5.6 字符串迭代
- **`for (c in s)` 迭代的是字节(`UInt8`/`Byte`)**,因为 `String` 实现了 `Collection<Byte>`(UTF-8 编码字节序列)
- **`for (c in s.runes())` 迭代的是字符(`Rune`)**,返回 `Iterator<Rune>`
- 这与大多数编程语言的行为不同,需要特别注意:
Expand Down
2 changes: 2 additions & 0 deletions skills/basic_programming_concepts/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ description: "仓颉语言基本编程概念。当需要了解仓颉语言的标
- `break` 退出循环,`continue` 跳至下一次迭代
- 二者的类型均为 `Nothing`

> **相关 Skill**:`match` 表达式和模式匹配详见 `cangjie-pattern-match` Skill;异常处理(`try`/`catch`/`throw`)详见 `cangjie-error-handle` Skill;Lambda 表达式和闭包详见 `cangjie-function` Skill

---

## 4. 函数(基本概念)
Expand Down
3 changes: 2 additions & 1 deletion skills/class/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ description: "仓颉语言类。当需要了解仓颉语言的类定义、抽象
- `sealed abstract class` — 仅同包内可继承
- `sealed` 隐含 `public`/`open` 语义
- `sealed` 的子类可不是 `sealed`,仍可被 `open`/`sealed` 修饰
- 若子类被 `open` 修饰,则其子类可在包外被继承
- 若子类被 `open` 修饰且不被 `sealed` 修饰,则其子类可在包外被继承
- `sealed` 类适用于限定继承范围,常与 `match` 穷举检查配合使用

### 3.3 父类构造函数调用
- 在子类 `init` 中:使用 `super(args)` 或 `this(args)` 作为函数体**第一个表达式**(互斥)
Expand Down
1 change: 1 addition & 0 deletions skills/collections/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ HashMap<Int64, Int64>(10, {x: Int64 => (x, x * x)}) // size=10,lambda
- **size 属性**:`map.size`
- **contains**:`map.contains("a")` → `Bool`
- **按键下标**:`map["a"]` — 键须存在否则**运行时异常**
- **安全访问**:`map.get("a")` — 返回 `?V`,键不存在时返回 `None`(不抛异常)

### 3.3 修改
- **下标赋值(更新)**:`map["a"] = 3`
Expand Down
3 changes: 1 addition & 2 deletions skills/concurrency/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ main(): Int64 {

### 3.1 `sleep()` 函数
- **签名**:`func sleep(dur: Duration): Unit`
- 阻塞当前线程至少 `dur` 时长
- **规则**:若 `dur <= Duration.Zero`,线程仅**让出**执行资源而不睡眠
- **规则**:阻塞当前线程**至少** `dur` 时长(实际可能略长)。若 `dur <= Duration.Zero`,线程仅**让出**执行资源而不睡眠

---

Expand Down
10 changes: 8 additions & 2 deletions skills/error_handle/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,14 @@ match (p) {

| 异常 | 说明 |
|------|------|
| `ConcurrentModificationException` | 并发修改错误 |
| `ArithmeticException` | 算术错误(如除以零) |
| `ConcurrentModificationException` | 迭代过程中集合被修改 |
| `IllegalArgumentException` | 非法或不正确的参数 |
| `IllegalStateException` | 对象处于非法状态 |
| `IndexOutOfBoundsException` | 数组/集合索引越界 |
| `NegativeArraySizeException` | 以负数大小创建数组 |
| `NoneValueException` | 值不存在 |
| `NoneValueException` | 尝试访问不存在的值(如对 `None` 解包) |
| `NullPointerException` | 空指针访问 |
| `OverflowException` | 算术溢出 |
| `UnsupportedException` | 不支持的操作 |
| `TimeoutException` | 操作超时 |
4 changes: 2 additions & 2 deletions skills/macro/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ description: "仓颉语言宏。当需要了解仓颉语言的Token/Tokens类型
| `parseType(Tokens)` | 解析为类型节点 `TypeNode` |
| `parsePattern(Tokens)` | 解析为模式节点 `Pattern` |
| `parseProgram(Tokens)` | 解析整个源文件为 `Program` 节点 |
| `parseExprFragment(Tokens, Int64)` | 部分解析表达式,返回 `(Expr, Int64)` |
| `parseDeclFragment(Tokens, Int64)` | 部分解析声明,返回 `(Decl, Int64)` |
| `parseExprFragment(Tokens, Int64)` | 从指定偏移处部分解析表达式,返回 `(Expr, Int64)` — 第二个 `Int64` 为解析结束后的新偏移 |
| `parseDeclFragment(Tokens, Int64)` | 从指定偏移处部分解析声明,返回 `(Decl, Int64)` — 第二个 `Int64` 为解析结束后的新偏移 |

也可通过直接构造函数创建节点:`BinaryExpr(quote(a + b))`、`FuncDecl(quote(func f1(...) {...}))` 等

Expand Down
Loading