proc 函数
定义可复用的过程,支持可选的类型化参数和局部声明。
语法
name := proc(x) return expr end procname := proc(x::integer) return expr end proc
参数与选项
parameter | 形式参数;可以包含 x::integer 等类型标注。 |
|---|---|
body | 以显示值或 return 表达式结束的语句序列。 |
示例
- 类型化过程
f := proc(x::integer) return x + 1 end proc; f(2)返回 3。 - 类型化参数错误
traperror(f := proc(x::integer) return x + 1 end proc; f(1/2))返回参数类型错误。