MarqdoEXECUTABLE KNOWLEDGE

Call one function: the same document is the toolok

features/22-call.mq.md

文档

怎样读这份可执行文档

正文说明意图,标记指出哪些片段会执行。遮蔽只在正文显示动作说明,实际逻辑放在侧注;阅读、展开与定位都不会运行代码。

标记阅读含义
无标记文字作者的解释,按普通 Markdown 阅读。
空行分隔叙述与结构,不是计算步骤。
# / ##一级标题声明对象或入口,更深标题声明函数;说明按钮可查看输入、返回与依据。
>调用函数;实际执行结果另有标注。
1. 递增按条件选择分支,不是普通编号说明。
-重复或遍历结构;迭代选择器只切换已有运行记录。
+ `名`兼容的显式形参;新库优先在叙述中声明参数,标题下的表格解释契约。
GFM 表未绑定的契约表是说明;绑定表按列、行和 @ 形态构成数据。
```lang代码块;绑定的外语代码与普通示例区分展示,数学公式另有公式卡片。
--- / ***分隔内容,不能把分隔线当作函数返回。
<!-- marqdo-out -->程序写回的结果,区别于作者原始正文。
`名`叙述中的参数或变量;默认值跟在名称之后。
**…**执行语句:赋值、调用或计算;不是打印,也不是返回。
*…*返回表达式;句中以返回、Return 等明确引出。
*None* / ****显式返回空值或结束当前函数。
[键](集合)正文显示描述,侧注按函数与参数、可跳转链接、结构化内容展示括号内的细节;空括号表示待补充实际逻辑。阅读不会执行调用。classic 模式保留旧链接取元。
修饰… [函数] …兼容的带修饰调用;不能把任意普通链接当作执行授权。
集合[^键]兼容的脚注取元;当前库优先用 access 读取集合。
*仅* / **说明**普通强调仍属于文字;界面按真实解析结果区分强调、语句与返回。

main

说明
返回类型说明
resultanyNone; execute this page's documented steps in order and observe their output or stated effects

v2.2.0 adds one command: marqdo call. It adds no Markdown marker and no skill system. An ordinary .mq.md file is already a document, a piece of knowledge and a program. What was missing is a way to call one of its functions from outside.

The usual command runs the whole file. Functions inside it run only when the entry calls them. Trying one calculation meant writing an entry, a print and a check. The smallest unit you can execute is now a function.

code text
marqdo call examples/calculator.mq.md 计算器.加法 a=2 b=3

Standard output is 5. --json is for programs and agents: success carries the result, failure carries a diagnostic code, and the process exits non-zero. --backend tree and --backend bytecode both run that function. Another entry in the file is not used as a fallback.

The second half of this page is itself a calculator. This command calls this page:

code text
marqdo call public/features/22-call.mq.md calculator.add a=2 b=3
---

The change is how the file is used.

A person reads the sentences next to the function and sees what add computes. The compiler reads the same markers and checks parameters and the return. A developer composes the function into another program. A test passes inputs to this function and looks at the output, without a wrapper whose only job is to print. An agent reads what the function is for and runs the implementation that is already there, instead of reading the page and rewriting it.

Those four uses are one call. Knowledge becomes a tool because knowledge can already run, now at function scope. The file does not need a special name, and it does not need to declare itself a skill.

---

The command keeps a boundary.

An external call defaults to a pure function. Writing files, starting a process, using the network or loading a plugin is refused before the function runs. Pass --effects plugin when the tool needs an ABI plugin (for example ext/quantum). Session bindings use --session and --toget name (or trailing toget name); later calls may pass $name. Nested sub-tools use a dotted path such as outer.helper. An instance method needs its receiver; this command does not invent one.

The function must resolve to exactly one declaration. No match, or one short name that hits two functions, is a structured error. The command does not pick the first hit. Arguments bind through the signature and contract that the function already has. Missing, unknown and ill-typed arguments are diagnostics.

After editing a function, call it again with the inputs that failed. A passing check is a reason to keep the edit. A test does not prove every input. It gives the edit a check that can be repeated.

calculator

说明
返回类型说明
resultanyObject/type namespace for the child functions below; call the intended child directly

This is an ordinary Marqdo document.

It holds a little reusable arithmetic.

add

说明
ab
参数类型默认说明
aanyrequiredLeft operand supplied to this calculation
banyrequiredRight operand supplied to this calculation
返回类型说明
resultanyThe value explicitly returned below; conditional returns follow the selected branch

Add the numbers a and b.

After these steps, return .
表达式result
`a` + `b`
原始写法
(`a` + `b`)
源码说明 · 不是运行结果

multiply

说明
ab
参数类型默认说明
aanyrequiredLeft operand supplied to this calculation
banyrequiredRight operand supplied to this calculation
返回类型说明
resultanyThe value explicitly returned below; conditional returns follow the selected branch

Multiply the numbers a and b.

After these steps, return .
表达式result
`a` * `b`
原始写法
(`a` * `b`)
源码说明 · 不是运行结果
Functions
Variables
  • description text
    v2.2.0 marqdo call runs a function inside any .mq.md. The explanation, the implementation and the call are one page.
  • markup text
    occlusion
  • title text
    Call one function: the same document is the tool
可执行知识 · 输入、返回与依据

这份文档怎样成为可调用的知识

4 个知识单元 · 4 个结构步骤。先读输入、返回与调用边界,再按需查看依赖和依据。

以下来自静态分析,不代表程序已经运行、测试通过或内容已获领域确认。实际运行见正文标注与“运行与结果”。

main程序入口
回到正文 · 第 7 行

这是程序入口或对象声明。成员函数的输入输出在各自说明中列出。

源码中的返回契约

any · None; execute this page's documented steps in order and observe their output or stated effects

调用边界

无已知宿主副作用。权限由实际运行入口授予;静态副作用信息不等于运行许可。

当前有哪些依据

语法与引用
检查通过;检查通过
契约检查
尚未检查
测试记录
没有可用记录
内容来源
尚无已核验证据
领域审阅
尚未进行领域审阅
技术详情:身份、摘要与原始状态
目标标识
mq://public/features%2F22-call/type/main
制品摘要(未检查锁定状态)
sha256:2839b0a3cf2c13e0d83cff6a9cae1807187aff52086ff61672e5cb3ed857912e
依赖标识
原始验证状态
parse: passed; resolve: passed; contract: unchecked; execution: not_run; tests: unknown; evidence: unverified; domain: unreviewed
calculator对象
回到正文 · 第 47 行

这是程序入口或对象声明。成员函数的输入输出在各自说明中列出。

源码中的返回契约

any · Object/type namespace for the child functions below; call the intended child directly

调用边界

无已知宿主副作用。权限由实际运行入口授予;静态副作用信息不等于运行许可。

当前有哪些依据

语法与引用
检查通过;检查通过
契约检查
尚未检查
测试记录
没有可用记录
内容来源
尚无已核验证据
领域审阅
尚未进行领域审阅
技术详情:身份、摘要与原始状态
目标标识
mq://public/features%2F22-call/type/calculator
制品摘要(未检查锁定状态)
sha256:2839b0a3cf2c13e0d83cff6a9cae1807187aff52086ff61672e5cb3ed857912e
依赖标识
原始验证状态
parse: passed; resolve: passed; contract: unchecked; execution: not_run; tests: unknown; evidence: unverified; domain: unreviewed
calculator.add函数
回到正文 · 第 57 行

需要什么输入

参数类型提供方式含义
aany必填Left operand supplied to this calculation
bany必填Right operand supplied to this calculation

返回什么

any · The value explicitly returned below; conditional returns follow the selected branch

调用边界

无已知宿主副作用。权限由实际运行入口授予;静态副作用信息不等于运行许可。

当前有哪些依据

语法与引用
检查通过;检查通过
契约检查
尚未检查
测试记录
没有可用记录
内容来源
尚无已核验证据
领域审阅
尚未进行领域审阅
查看本单元的结构步骤

这是源码结构,不是实际执行时序;正文引用不会因阅读而执行。

  1. 计算result
  2. 正文引用result
技术详情:身份、摘要与原始状态
目标标识
mq://public/features%2F22-call/function/calculator/add
制品摘要(未检查锁定状态)
sha256:08f3bad1c984a2f6798118b9770ab8fe60ffea12f23cba9222da8454c95d4a97
依赖标识
原始验证状态
parse: passed; resolve: passed; contract: unchecked; execution: not_run; tests: unknown; evidence: unverified; domain: unreviewed
calculator.multiply函数
回到正文 · 第 72 行

需要什么输入

参数类型提供方式含义
aany必填Left operand supplied to this calculation
bany必填Right operand supplied to this calculation

返回什么

any · The value explicitly returned below; conditional returns follow the selected branch

调用边界

无已知宿主副作用。权限由实际运行入口授予;静态副作用信息不等于运行许可。

当前有哪些依据

语法与引用
检查通过;检查通过
契约检查
尚未检查
测试记录
没有可用记录
内容来源
尚无已核验证据
领域审阅
尚未进行领域审阅
查看本单元的结构步骤

这是源码结构,不是实际执行时序;正文引用不会因阅读而执行。

  1. 计算result
  2. 正文引用result
技术详情:身份、摘要与原始状态
目标标识
mq://public/features%2F22-call/function/calculator/multiply
制品摘要(未检查锁定状态)
sha256:550da7d30852e5ddf9b5b6dc08f5217ee50166e4b3c4136189997bd3c91338e6
依赖标识
原始验证状态
parse: passed; resolve: passed; contract: unchecked; execution: not_run; tests: unknown; evidence: unverified; domain: unreviewed

运行与结果

(no stdout)
完整源码
---
markup: occlusion
title: Call one function: the same document is the tool
description: v2.2.0 marqdo call runs a function inside any .mq.md. The explanation, the implementation and the call are one page.
---

# main

| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |

v2.2.0 adds one command: `marqdo call`. It adds no Markdown marker and no skill system. An ordinary .mq.md file is already a document, a piece of knowledge and a program. What was missing is a way to call one of its functions from outside.

The usual command runs the whole file. Functions inside it run only when the entry calls them. Trying one calculation meant writing an entry, a print and a check. The smallest unit you can execute is now a function.

```text
marqdo call examples/calculator.mq.md 计算器.加法 a=2 b=3
```

Standard output is 5. `--json` is for programs and agents: success carries the result, failure carries a diagnostic code, and the process exits non-zero. `--backend tree` and `--backend bytecode` both run that function. Another entry in the file is not used as a fallback.

The second half of this page is itself a calculator. This command calls this page:

```text
marqdo call public/features/22-call.mq.md calculator.add a=2 b=3
```

---

The change is how the file is used.

A person reads the sentences next to the function and sees what add computes. The compiler reads the same markers and checks parameters and the return. A developer composes the function into another program. A test passes inputs to this function and looks at the output, without a wrapper whose only job is to print. An agent reads what the function is for and runs the implementation that is already there, instead of reading the page and rewriting it.

Those four uses are one call. Knowledge becomes a tool because knowledge can already run, now at function scope. The file does not need a special name, and it does not need to declare itself a skill.

---

The command keeps a boundary.

An external call defaults to a pure function. Writing files, starting a process, using the network or loading a plugin is refused before the function runs. Pass `--effects plugin` when the tool needs an ABI plugin (for example `ext/quantum`). Session bindings use `--session` and `--toget name` (or trailing `toget name`); later calls may pass `$name`. Nested sub-tools use a dotted path such as `outer.helper`. An instance method needs its receiver; this command does not invent one.

The function must resolve to exactly one declaration. No match, or one short name that hits two functions, is a structured error. The command does not pick the first hit. Arguments bind through the signature and contract that the function already has. Missing, unknown and ill-typed arguments are diagnostics.

After editing a function, call it again with the inputs that failed. A passing check is a reason to keep the edit. A test does not prove every input. It gives the edit a check that can be repeated.

# calculator

| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Object/type namespace for the child functions below; call the intended child directly |

This is an ordinary Marqdo document.

It holds a little reusable arithmetic.

## add

| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | required | Left operand supplied to this calculation |
| b | any | required | Right operand supplied to this calculation |

| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | The value explicitly returned below; conditional returns follow the selected branch |

Add the numbers `a` and `b`.

After these steps, return *[result]((`a` + `b`))*.

## multiply

| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | required | Left operand supplied to this calculation |
| b | any | required | Right operand supplied to this calculation |

| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | The value explicitly returned below; conditional returns follow the selected branch |

Multiply the numbers `a` and `b`.

After these steps, return *[result]((`a` * `b`))*.

Variable