Document workspace ownership, resource semantics and agent lifecycle
This commit is contained in:
@@ -4,10 +4,10 @@
|
||||
|
||||
## 9.1 函数声明
|
||||
|
||||
代码归属:`alice:shop.pricing`。
|
||||
代码归属:`atelier:shop.pricing`。
|
||||
|
||||
```endorphin
|
||||
function discountedPrice(price: Int, discount: Int): Int {
|
||||
function discountedPrice(price: Number, discount: Number): Number {
|
||||
return price - discount
|
||||
}
|
||||
```
|
||||
@@ -18,8 +18,8 @@ function discountedPrice(price: Int, discount: Int): Int {
|
||||
| --- | --- |
|
||||
| `function` | 函数声明关键字 |
|
||||
| `discountedPrice` | 函数名 |
|
||||
| `price: Int, discount: Int` | 两个输入参数及其类型 |
|
||||
| 参数列表后的 `: Int` | 返回类型 |
|
||||
| `price: Number, discount: Number` | 两个输入参数及其类型 |
|
||||
| 参数列表后的 `: Number` | 返回类型 |
|
||||
| 花括号内的内容 | 函数体 |
|
||||
|
||||
参数按逗号分隔,每个参数都有名称与类型。本文基本函数体由零个或多个 let 绑定和一个末尾 return 组成;完整控制流另列于[规范状态](../appendices/specification-status.md#声明与类型)。
|
||||
@@ -28,16 +28,16 @@ function discountedPrice(price: Int, discount: Int): Int {
|
||||
|
||||
`return 表达式` 产生函数结果。表达式的类型必须符合返回类型。
|
||||
|
||||
discountedPrice 返回两个整数的差值。对于输入 `100` 与 `10`,成功结果为 `90`。定义函数不立即执行它;执行发生在 inflight 调用中。
|
||||
discountedPrice 返回两个数值的差值。对于输入 `100` 与 `10`,成功结果为 `90`。定义函数不立即执行它;执行发生在 inflight 调用中。
|
||||
|
||||
## 9.3 跨 namespace 调用
|
||||
|
||||
代码归属:`bob:shop.checkout`。
|
||||
代码归属:`market:shop.checkout`。
|
||||
|
||||
```endorphin
|
||||
use alice:shop.pricing
|
||||
use atelier:shop.pricing
|
||||
|
||||
function payable(price: Int, discount: Int): Int {
|
||||
function payable(price: Number, discount: Number): Number {
|
||||
let amount = discountedPrice(price, discount)
|
||||
return discountedPrice(amount, 5)
|
||||
}
|
||||
@@ -49,12 +49,12 @@ payable 引用定价 namespace,先使用原价与优惠额计算 amount,再
|
||||
|
||||
## 9.4 调用组合
|
||||
|
||||
代码归属:`bob:shop.ui`。业务函数声明:
|
||||
代码归属:`market:shop.ui`。业务函数声明:
|
||||
|
||||
```endorphin
|
||||
use bob:shop.checkout
|
||||
use market:shop.checkout
|
||||
|
||||
function checkoutAmount(): Int {
|
||||
function checkoutAmount(): Number {
|
||||
return payable(100, 10)
|
||||
}
|
||||
```
|
||||
@@ -72,7 +72,7 @@ checkoutAmount 的成功结果为 `85`。它不需要重复实现价格计算,
|
||||
- return 表达式是否符合返回类型。
|
||||
- 使用调用结果的后续表达式是否合法。
|
||||
|
||||
例如,discountedPrice 需要两个整数参数。`discountedPrice(100)` 数量不符;`discountedPrice("100", 10)` 在本文不进行隐式字符串到整数转换的示例条件下类型不符。
|
||||
例如,discountedPrice 需要两个数值参数。`discountedPrice(100)` 数量不符;`discountedPrice("100", 10)` 在本文不进行隐式文本到数值转换的示例条件下类型不符。
|
||||
|
||||
## 9.6 inflight 行为
|
||||
|
||||
|
||||
Reference in New Issue
Block a user