📝 docs(tsl): align syntax annotations and examples

This commit is contained in:
csh
2026-01-11 12:53:30 +08:00
parent 37546fe4f7
commit e3ecd26a88
5 changed files with 219 additions and 135 deletions
+24
View File
@@ -8,6 +8,7 @@
- [目录](#目录)
- [函数定义体和函数](#函数定义体和函数)
- [概念](#概念)
- [参数类型与返回类型](#参数类型与返回类型)
- [主函数与子函数](#主函数与子函数)
- [形式参数与实际参数](#形式参数与实际参数)
- [值参数](#值参数)
@@ -71,6 +72,29 @@ TSL 仅允许 `return` 一个值,如果需要返回多个内容,建议用数
```tsl
return array(x, y);
```
### 参数类型与返回类型
函数参数与返回值可以在名称后使用 `:` 指定类型,类型注解可选。注解名称不参与编译检查,可任意命名,仅用于说明与阅读。
参数分隔规则:
- 不带类型注解时,用逗号分隔参数,例如 `function f1(a, b);`
- 带类型注解时,用分号分隔参数,例如 `function f2(a: string; b: array of real);`
- 返回值类型在 `)` 之后定义,例如 `function f3(): void;`
```tsl
function SafeConvert(value: input_value; convert_func: handler): real;
begin
return ##convert_func(value);
end;
function Open(path: string; flags: options = 0): result;
begin
return array("path": path, "flags": flags);
end;
```
### 主函数与子函数
在 TSL 语言中,根据函数的可使用范围,将函数分成主函数和子函数两种。