Release 2.7.0: executable handbooks and native user-site workflows

This commit is contained in:
cflmy committed 2026-11-10 17:03:06 +08:00
1 parent aa0c4d0f55
commit d9aef957f7
562 files changed
+21064 -20387

No files matched your search

+5 -1
View File
@@ -6,6 +6,10 @@ description: How to import official lib modules
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
Version 2.6.0: each standard library is normally one lib/name.mq.md source file, which is its own handbook. No extra index is required. Read the parameter/default and return tables below its headings to call it; multi-file extensions use indexes to organize modules. The 61 public sources provide 650 functions.
Import with a nested YAML import mapping. File, network and process effects still need authorization at the execution entry. marqdo call defaults to pure functions; file operations require explicit --effects and --fs-root. Contract documentation never grants permission.
@@ -26,4 +30,4 @@ Official optional extensions live under ext/ (not stdlib): ext/llm, ext/agent
Sibling pages in this folder document each module. Chinese overview: 00-索引.mq.md.
> print text=stdlib overview ok
We now **[Display this step's result](> print text="stdlib overview ok")**.
+5 -1
View File
@@ -6,6 +6,10 @@ description: 如何导入官方 lib 模块
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
版本 2.6.0:标准库通常是单个 lib/名称.mq.md 文件,源码本身就是手册,不要求额外 index。直接阅读标题下的参数、默认值和返回表即可调用;多文件拓展库才通过 index 组织模块。当前 61 份公开标准库包含 650 个函数。
使用 YAML 的 import(或导入)映射导入模块。文件、网络、进程等副作用仍由运行入口授权;marqdo call 默认只运行纯函数,文件调用要明确 --effects 与 --fs-root。文档契约不会自动授予权限。
@@ -26,4 +30,4 @@ description: 如何导入官方 lib 模块
各模块说明见本目录其它页。English: 00-overview.mq.md.
> 打印 内容=标准库总览就绪
随后我们**[显示当前步骤的结果](> 打印 内容="标准库总览就绪")**。
+31 -26
View File
@@ -9,6 +9,10 @@ stdin: 21
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
`lib/foreign` runs code fences and inline sources with local interpreters. v2 keeps the Markdown surface unchanged while adding structured records, JSON in/out, parallel fan-out, persistent Python/Node kernels and an explicit state bridge.
The same file is still a document: a bound fence is readable Markdown, and `foreign.*` turns it into an executable unit.
@@ -17,10 +21,10 @@ The same file is still a document: a bound fence is readable Markdown, and `fore
Probe before you run.
**node = > foreign.probe lang="node"**
We first **node = [Compute node](foreign.probe(lang="node"))** for the next step.
> print text=[ok](access(`node`, "ok"))
> print text=[version](access(`node`, "version"))
We now **[Display this step's result](> print text=[ok](access(`node`, "ok")))**.
We now **[Display this step's result](> print text=[version](access(`node`, "version")))**.
`probe` returns `{lang, cmd, path, ok, version, error}`. Omit `lang` to inspect every known language.
@@ -30,14 +34,14 @@ A structured record, not just stdout.
`marker` =
```node
console.log("hello from a foreign kernel");
console.log(new Intl.NumberFormat("en-US", {style:"currency", currency:"CNY"}).format(950));
```
**record = > foreign.invoke code=`marker`**
We first **record = [Compute record](foreign.invoke(code=`marker`))** for the next step.
> print text=[ok](access(`record`, "ok"))
> print text=[stdout](access(`record`, "stdout"))
> print text=[code](access(`record`, "code"))
We now **[Display this step's result](> print text=[ok](access(`record`, "ok")))**.
We now **[Display this step's result](> print text=[stdout](access(`record`, "stdout")))**.
We now **[Display this step's result](> print text=[code](access(`record`, "code")))**.
`invoke` never throws on a process failure. Read `ok`, `code`, `stdout`, `stderr`, `ms`, `timed_out`, `truncated`, `result` and `error` from one record.
@@ -45,18 +49,18 @@ console.log("hello from a foreign kernel");
JSON in, JSON out.
`double` =
`format_money` =
```node
let input = "";
process.stdin.on("data", chunk => { input += chunk; });
process.stdin.on("end", () => {
console.log(JSON.stringify(JSON.parse(input) * 2));
console.log(JSON.stringify(new Intl.NumberFormat("en-US", {style:"currency", currency:"CNY"}).format(JSON.parse(input))));
});
```
**single = > foreign.call code=`double` input=21**
We first **single = [Compute single](foreign.call(code=`format_money`, input=21))** for the next step.
> print text=`single`
We now **[Display this step's result](> print text=`single`)**.
The input is encoded as JSON on stdin; the last stdout value is parsed as JSON. Use `output="json"` with `invoke` when you also want the raw record.
@@ -73,9 +77,10 @@ Parallel fan-out.
| 3 |
| 4 |
**doubled = > foreign.call_many code=`double` inputs=`numbers` concurrency=4**
This single-column bound table is a native list of numbers, ready for the batch call.
We **formatted_batch = [Format each amount while retaining input order](foreign.call_many(code=`format_money`, inputs=`numbers`, concurrency=4))**.
> print text=`doubled`
We now **[Display this step's result](> print text=`formatted_batch`)**.
`call_many` applies one program to every input, runs independently, preserves input order, and returns parsed JSON results. `run_many` does the same for full invoke-option maps.
@@ -83,13 +88,13 @@ Parallel fan-out.
A persistent kernel.
**session = > foreign.session_open lang="node"**
We first **session = [Compute session](foreign.session_open(lang="node"))** for the next step.
**first = > foreign.session_eval id=`session` source="let total = 0; for (let i = 1; i <= 5; i += 1) total += i;"**
We first **first = [Compute first](foreign.session_eval(id=`session`, source="var money = new Intl.NumberFormat(\"en-US\", {style:\"currency\", currency:\"CNY\"});"))** for the next step.
**second = > foreign.session_eval id=`session` source="total * 2"**
We first **second = [Compute second](foreign.session_eval(id=`session`, source="money.format(21)"))** for the next step.
> print text=[result](access(`second`, "result"))
We now **[Display this step's result](> print text=[result](access(`second`, "result")))**.
Variables created in the first evaluation survive into the second. The kernel is not a shell: use `session_eval`, `session_get`, `session_names`, then `session_close`.
@@ -97,13 +102,13 @@ Variables created in the first evaluation survive into the second. The kernel is
The explicit state bridge.
**> foreign.session_set id=`session` name="rate" value=0.08**
We **[Copy the explicit rate into the existing kernel](foreign.session_set(id=`session`, name="rate", value=0.08))**.
**rate = > foreign.session_get id=`session` name="rate"**
We first **rate = [Compute rate](foreign.session_get(id=`session`, name="rate"))** for the next step.
> print text=`rate`
We now **[Display this step's result](> print text=`rate`)**.
**> foreign.session_close id=`session`**
After reading the copied value, we **[Close this persistent formatting kernel](foreign.session_close(id=`session`))**.
This is a JSON copy, not shared memory. The kernel receives a value; Marqdo receives a value. There is no implicit mirroring and no hidden global namespace.
@@ -118,8 +123,8 @@ Cells in view.
| 名称 | 语言 | 命令 | 说明 |
|------|------|------|------|
| 分析 | python | | shared analysis |
| 复核 | python | | isolated review |
| 分析 | node | | shared analysis |
| 复核 | node | | isolated review |
`分析单元` =
@@ -132,7 +137,7 @@ Cells in view.
`会话` = > foreign.session kernels=`分析内核` cells=`分析单元`
```
`view` consumes the `会话` handle and adds Run All, Step, kernel switching, a journal and per-cell state. Without `会话`, view cells are stateless one-shot runs: same shell, no persistent kernel. There is no second CLI mode. See the complete Python walkthrough in [`features/19-foreign-view-cells.mq.md`](../features/19-foreign-view-cells.mq.md).
`view` consumes the `会话` handle and adds Run All, Step, kernel switching, a journal and per-cell state. Without `会话`, view cells are stateless one-shot runs: same shell, no persistent kernel. There is no second CLI mode. See the native-first Intl workflow in [`features/19-foreign-view-cells.mq.md`](../features/19-foreign-view-cells.mq.md).
---
@@ -144,7 +149,7 @@ Safety defaults.
| Shell | no shell; arguments are split explicitly |
| Output | bounded, with truncated |
| Timeout | process group killed on Unix / taskkill /T on Windows |
| CWD | file sandbox root; no implicit escape |
| CWD | starts at the granted root; the child retains normal OS authority |
| Parallelism | capped fan-out; each item isolated |
Read the full API in [../../lib/foreign.mq.md](../../lib/foreign.mq.md) and the design in [../../doc/design/foreign-kernel.md](../../doc/design/foreign-kernel.md).
+5 -1
View File
@@ -8,9 +8,13 @@ import:
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
Filesystem helpers from lib/fs. Bare path words must not contain `/` (division). Prefer a same-folder name or a variable.
**`ok` = [fs.exists] path="demo.txt"**
We first **ok = [Compute ok](fs.exists(path="demo.txt"))** for the next step.
1. `ok`
**打印 内容="demo-present"**
+7 -3
View File
@@ -8,12 +8,16 @@ import:
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
Shared JSON helpers for EN and ZH docs. Prefer parse, stringify, and quote.
Build maps with tables or table.put — not json.set chains.
**`obj` = [json.parse] text="{}"**
**`ty` = [type] `obj`**
We first **obj = [Compute obj](json.parse(text="{}"))** for the next step.
We first **ty = [Compute ty](type(`obj`))** for the next step.
**打印 内容=`ty`**
**`out` = [json.stringify] value=`obj`**
We first **out = [Compute out](json.stringify(value=`obj`))** for the next step.
**打印 内容=`out`**
+12 -8
View File
@@ -8,6 +8,10 @@ import:
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
Import lib/math.mq.md. Runtime types: num (float) and formula (symbolic tree). Bind a formula with an empty-RHS assign followed by a `$$…$$` fence (same shape as table assigns). In view, Structure renders that fence with KaTeX.
`f` =
@@ -23,18 +27,18 @@ Plotting (already in the library): plot / plot_points / plot_conic return SVG te
diff / simplify / expand / partial subs return formula values so you can chain (e.g. differentiate twice, then plot or eval).
**`ty` = [type] `f`**
We first **ty = [Compute ty](type(`f`))** for the next step.
> print text=`ty`
We now **[Display this step's result](> print text=`ty`)**.
**`df` = [math.diff] formula=`f` var="x"**
We first **df = [Compute df](math.diff(formula=`f`, var="x"))** for the next step.
> print text=`df`
We now **[Display this step's result](> print text=`df`)**.
**`roots` = [math.solve] formula=`f` var="x"**
We first **roots = [Compute roots](math.solve(formula=`f`, var="x"))** for the next step.
> print text=`roots`
We now **[Display this step's result](> print text=`roots`)**.
**`_svg` = [math.plot] formula=`f` var="x" min=-3 max=3**
We first **_svg = [Compute _svg](math.plot(formula=`f`, var="x", min=-3, max=3))** for the next step.
> print text=plot-ok
We now **[Display this step's result](> print text="plot-ok")**.
+6 -2
View File
@@ -8,8 +8,12 @@ import:
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
Import lib/net.mq.md. Functions: http_get, http_post, http_post_sse, openai_sse_parse, http_request, url_encode. HTTPS and optional headers= map are supported. Default post content-type is JSON. `http_post_sse` / `openai_sse_parse` return OpenAI chat stream event lists (`delta` / `done`).
**`e` = [net.url_encode] text="hello world"**
We first **e = [Compute e](net.url_encode(text="hello world"))** for the next step.
> print text=`e`
We now **[Display this step's result](> print text=`e`)**.
+8 -4
View File
@@ -8,13 +8,17 @@ import:
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
Import lib/plugin.mq.md. Functions: load(path), unload(), list(). After load, registered plugin names are callable like other functions. C ABI: include/marqdo_abi.h — see doc/design/ext-abi.md. Path must stay under the program sandbox (cwd / fs root).
**`names` = [plugin.list]**
We first **names = [Compute names](plugin.list())** for the next step.
**`n` = [len] `names`**
We first **n = [Compute n](len(`names`))** for the next step.
1. `n` >= 0
> print text=plugin-ok
We now **[Display this step's result](> print text="plugin-ok")**.
2. *
> print text=plugin-bad
We now **[Display this step's result](> print text="plugin-bad")**.
+5 -1
View File
@@ -8,6 +8,10 @@ import:
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
spawn picks one mode (others default to None).
path= runs a marqdo run child process; wait returns the exit code.
@@ -20,4 +24,4 @@ lang= plus source= runs foreign source; wait returns stdout text.
File children are silent unless quiet=False. Also: poll id=, kill id=, wait_all. Parent exit kills file/foreign children.
> print text=subtask overview ok
We now **[Display this step's result](> print text="subtask overview ok")**.
+8 -4
View File
@@ -8,13 +8,17 @@ import:
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
Import lib/sys.mq.md. Functions: env_get, env_set, load_dotenv(optional path), args, cwd, exit(code), exec(cmd), stream_publish(event). load_dotenv does not override existing variables. Under view, exit soft-fails instead of killing the process. `stream_publish` feeds the view SSE EventBus.
**`d` = [sys.cwd]**
We first **d = [Compute d](sys.cwd())** for the next step.
**`n` = [len] `d`**
We first **n = [Compute n](len(`d`))** for the next step.
1. `n` > 0
> print text=cwd-ok
We now **[Display this step's result](> print text="cwd-ok")**.
2. *
> print text=cwd-empty
We now **[Display this step's result](> print text="cwd-empty")**.
+7 -3
View File
@@ -8,10 +8,14 @@ import:
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
Prefer table.put for element updates (at= text key, 1-based int, or list path).
Read with link-index get. Use json for parse/stringify only.
**`h` = [table.put] in=None at="Authorization" value="Bearer-demo"**
We first **h = [Compute h](table.put(in=None, at="Authorization", value="Bearer-demo"))** for the next step.
`xs` =
@@ -20,8 +24,8 @@ Read with link-index get. Use json for parse/stringify only.
| a |
| b |
**`xs` = [table.put] in=`xs` at=1 value="A"**
**`n` = [table.rows] xs=`xs`**
We first **xs = [Compute xs](table.put(in=`xs`, at=1, value="A"))** for the next step.
We first **n = [Compute n](table.rows(xs=`xs`))** for the next step.
**打印 内容=[Authorization](access(h, "Authorization"))**
**打印 内容=[1](access(xs, "1"))**
+7 -3
View File
@@ -8,11 +8,15 @@ import:
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
Import lib/text. Bracket path or classic dotted calls both work.
**`t` = [text.str_trim] s=" marqdo "**
We first **t = [Compute t](text.str_trim(s=" marqdo "))** for the next step.
**打印 内容=`t`**
**`parts` = [text.str_split] s="a,b,c" sep=","**
**`j` = [text.str_join] xs=`parts` sep="-"**
We first **parts = [Compute parts](text.str_split(s="a,b,c", sep=","))** for the next step.
We first **j = [Compute j](text.str_join(xs=`parts`, sep="-"))** for the next step.
**打印 内容=`j`**
+6 -2
View File
@@ -8,12 +8,16 @@ import:
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
Unix time helpers from lib/time. Patterns use strftime.
**`s` = [time.format] unix=0 pattern="%Y-%m-%d"**
We first **s = [Compute s](time.format(unix=0, pattern="%Y-%m-%d"))** for the next step.
**打印 内容=`s`**
**`u` = [time.parse] text="1970-01-01 00:00:00" pattern="%Y-%m-%d %H:%M:%S"**
We first **u = [Compute u](time.parse(text="1970-01-01 00:00:00", pattern="%Y-%m-%d %H:%M:%S"))** for the next step.
**打印 内容=`u`**
**[time.sleep_ms] ms=0**
+5 -1
View File
@@ -8,6 +8,10 @@ import:
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
Writeback stores output in `<!-- marqdo-out … -->` blocks in the **entry** file (the one you run).
record value= — default: insert or replace the block below the call; at_end=true → single block at EOF.
@@ -16,4 +20,4 @@ get / clear — read or remove the adjacent block (or EOF block when at_end=true
list — all output blocks in the entry file.
> print text=writeback overview ok
We now **[Display this step's result](> print text="writeback overview ok")**.
+30 -25
View File
@@ -9,6 +9,10 @@ stdin: 21
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
`lib/外联` 用本机解释器运行代码围栏和内联源码。v2 不改 Markdown 表面,新增结构化记录、JSON 进出、并行扇出、Python/Node 持久内核和显式状态桥。
文件仍然是一篇文档:绑定的代码围栏是可读的 Markdown,`外联.*` 把它变成可执行单元。
@@ -17,10 +21,10 @@ stdin: 21
先探测,再运行。
**node = > 外联.探测 语言="node"**
我们先**node = [计算并保存 node](外联.探测(语言="node"))**,供下一步使用。
> 打印 内容=[ok](access(`node`, "ok"))
> 打印 内容=[version](access(`node`, "version"))
随后我们**[显示当前步骤的结果](> 打印 内容=[ok](access(`node`, "ok")))**。
随后我们**[显示当前步骤的结果](> 打印 内容=[version](access(`node`, "version")))**。
`探测` 返回 `{lang, cmd, path, ok, version, error}`。省略语言时探测所有已知语言。
@@ -30,14 +34,14 @@ stdin: 21
`标记` =
```node
console.log("来自外联内核的问候");
console.log(new Intl.NumberFormat("zh-CN", {style:"currency", currency:"CNY"}).format(950));
```
**记录 = > 外联.执行 代码=`标记`**
我们先**记录 = [计算并保存 记录](外联.执行(代码=`标记`))**,供下一步使用。
> 打印 内容=[ok](access(`记录`, "ok"))
> 打印 内容=[stdout](access(`记录`, "stdout"))
> 打印 内容=[code](access(`记录`, "code"))
随后我们**[显示当前步骤的结果](> 打印 内容=[ok](access(`记录`, "ok")))**。
随后我们**[显示当前步骤的结果](> 打印 内容=[stdout](access(`记录`, "stdout")))**。
随后我们**[显示当前步骤的结果](> 打印 内容=[code](access(`记录`, "code")))**。
`执行` 在进程失败时不抛错,而是在一条记录里给出 `ok`、`code`、`stdout`、`stderr`、`ms`、`timed_out`、`truncated`、`result` 与 `error`。
@@ -45,18 +49,18 @@ console.log("来自外联内核的问候");
JSON 进,JSON 出。
`双倍` =
`金额格式` =
```node
let input = "";
process.stdin.on("data", chunk => { input += chunk; });
process.stdin.on("end", () => {
console.log(JSON.stringify(JSON.parse(input) * 2));
console.log(JSON.stringify(new Intl.NumberFormat("zh-CN", {style:"currency", currency:"CNY"}).format(JSON.parse(input))));
});
```
**单个 = > 外联.调用 代码=`双倍` 输入=21**
我们先**单个 = [计算并保存 单个](外联.调用(代码=`金额格式`, 输入=21))**,供下一步使用。
> 打印 内容=`单个`
随后我们**[显示当前步骤的结果](> 打印 内容=`单个`)**。
输入编码成 JSON 写到 stdin;stdout 的最后一个值再解析成 JSON。想同时保留原始记录时,用 `执行` 的 `输出="json"`。
@@ -73,9 +77,10 @@ process.stdin.on("end", () => {
| 3 |
| 4 |
**翻倍 = > 外联.批量调用 代码=`双倍` 输入表=`数值表` 并发=4**
这张单列绑定表本身就是原生数值列表,可以直接交给批量调用。
随后我们**格式列表 = [并行展示金额并保持输入顺序](外联.批量调用(代码=`金额格式`, 输入表=`数值表`, 并发=4))**。
> 打印 内容=`翻倍`
随后我们**[显示当前步骤的结果](> 打印 内容=`格式列表`)**。
`批量调用` 对每个输入独立运行同一程序,保持输入顺序并返回解析后的 JSON 列表;`批量运行` 对完整 invoke 选项表做同样的事。
@@ -83,13 +88,13 @@ process.stdin.on("end", () => {
持久内核。
**会话 = > 外联.会话开启 语言="node"**
我们先**会话 = [计算并保存 会话](外联.会话开启(语言="node"))**,供下一步使用。
**第一次 = > 外联.会话求值 标识=`会话` 源码="let total = 0; for (let i = 1; i <= 5; i += 1) total += i;"**
我们先**第一次 = [计算并保存 第一次](外联.会话求值(标识=`会话`, 源码="var money = new Intl.NumberFormat(\"zh-CN\", {style:\"currency\", currency:\"CNY\"});"))**,供下一步使用。
**第二次 = > 外联.会话求值 标识=`会话` 源码="total * 2"**
我们先**第二次 = [计算并保存 第二次](外联.会话求值(标识=`会话`, 源码="money.format(21)"))**,供下一步使用。
> 打印 内容=[result](access(`第二次`, "result"))
随后我们**[显示当前步骤的结果](> 打印 内容=[result](access(`第二次`, "result")))**。
第一次求值创建的变量会保留到第二次。内核不是 shell:用 `会话求值`、`会话取值`、`会话变量`,最后 `会话关闭`。
@@ -97,13 +102,13 @@ process.stdin.on("end", () => {
显式状态桥。
**> 外联.会话设值 标识=`会话` 名称="rate" 值=0.08**
我们**[将明确选定的值复制进已有内核](外联.会话设值(标识=`会话`, 名称="rate", 值=0.08))**。
**利率 = > 外联.会话取值 标识=`会话` 名称="rate"**
我们先**利率 = [计算并保存 利率](外联.会话取值(标识=`会话`, 名称="rate"))**,供下一步使用。
> 打印 内容=`利率`
随后我们**[显示当前步骤的结果](> 打印 内容=`利率`)**。
**> 外联.会话关闭 标识=`会话`**
读回所需结果后,我们**[关闭本次持久展示内核](外联.会话关闭(标识=`会话`))**。
这是 JSON 拷贝,不是共享内存:内核收到一个值,Marqdo 取回一个值。没有隐式镜像,也没有隐藏的全局命名空间。
@@ -118,8 +123,8 @@ view 中的单元。
| 名称 | 语言 | 命令 | 说明 |
|------|------|------|------|
| 分析 | python | | 共享分析 |
| 复核 | python | | 独立复核 |
| 分析 | node | | 共享分析 |
| 复核 | node | | 独立复核 |
`分析单元` =
@@ -132,7 +137,7 @@ view 中的单元。
`会话` = > foreign.session kernels=`分析内核` cells=`分析单元`
```
`view` 消费 `会话` 句柄,提供 Run All、Step、切换内核、journal 和单元状态。没有 `会话` 时,view 的 cells 是无状态的一次性运行:同一套外壳,但没有持久内核。没有第二个 CLI 模式。完整 Python 示例见 [`features/19-外联视图单元.mq.md`](../features/19-外联视图单元.mq.md)。
`view` 消费 `会话` 句柄,提供 Run All、Step、切换内核、journal 和单元状态。没有 `会话` 时,view 的 cells 是无状态的一次性运行:同一套外壳,但没有持久内核。没有第二个 CLI 模式。原生分析与 Intl 示例见 [`features/19-外联视图单元.mq.md`](../features/19-外联视图单元.mq.md)。
---
+5 -1
View File
@@ -8,6 +8,10 @@ description: 文件、函数或外联代码并行执行
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
启动(spawn)四选一(其余参数默认 None)。
路径=:marqdo run 子进程;等待返回退出码。
@@ -20,4 +24,4 @@ description: 文件、函数或外联代码并行执行
文件子任务默认静默;静默=假 时继承父终端。另有:探测、终止、等待全部。父进程结束会终止文件/外联子进程。
> 打印 内容=子任务总览就绪
随后我们**[显示当前步骤的结果](> 打印 内容="子任务总览就绪")**。
+8 -4
View File
@@ -8,13 +8,17 @@ description: 加载可选共享库(.dll / .so / .dylib)
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
导入 lib/插件.mq.md。函数:加载(路径)、卸载()、列出()。加载后,插件注册的名称可像普通函数一样调用。C 契约见 include/marqdo_abi.h 与 doc/design/ext-abi.md。路径须落在程序沙箱内。
**`names` = [插件.列出]**
我们先**names = [计算并保存 names](插件.列出())**,供下一步使用。
**`n` = [长度] 值=`names`**
我们先**n = [计算并保存 n](长度(值=`names`))**,供下一步使用。
1. `n` >= 0
> 打印 内容=插件就绪
随后我们**[显示当前步骤的结果](> 打印 内容="插件就绪")**。
2. *
> 打印 内容=插件异常
随后我们**[显示当前步骤的结果](> 打印 内容="插件异常")**。
+12 -8
View File
@@ -8,6 +8,10 @@ description: 高中数学标准库(中文)
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
导入 lib/数学.mq.md。运行时类型:num(浮点)与 formula(符号树)。用空 RHS 赋值后跟 `$$…$$` 围栏绑定公式(与表格赋值同构)。view 的 Structure 会用 KaTeX 渲染该公式。
`f` =
@@ -23,18 +27,18 @@ $$
求导 / 化简 / 展开 / 未完全数值化的代入仍返回 formula,可继续链式调用(例如求二阶导后再绘图或求值)。
**`ty` = [type] `f`**
我们先**ty = [计算并保存 ty](type(`f`))**,供下一步使用。
> print text=`ty`
随后我们**[显示当前步骤的结果](> print text=`ty`)**。
**`df` = [数学.求导] formula=`f` var="x"**
我们先**df = [计算并保存 df](数学.求导(formula=`f`, var="x"))**,供下一步使用。
> print text=`df`
随后我们**[显示当前步骤的结果](> print text=`df`)**。
**`roots` = [数学.求解] formula=`f` var="x"**
我们先**roots = [计算并保存 roots](数学.求解(formula=`f`, var="x"))**,供下一步使用。
> print text=`roots`
随后我们**[显示当前步骤的结果](> print text=`roots`)**。
**`_svg` = [数学.绘图] formula=`f` var="x" min=-3 max=3**
我们先**_svg = [计算并保存 _svg](数学.绘图(formula=`f`, var="x", min=-3, max=3))**,供下一步使用。
> print text=plot-ok
随后我们**[显示当前步骤的结果](> print text="plot-ok")**。
+5 -1
View File
@@ -8,9 +8,13 @@ description: 沙箱内读写文本
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
文件系统助手(lib/文件)。裸路径不要写斜杠(会被当成除法)。可用同目录文件名或变量。
**`ok` = [文件.存在] 路径="demo.txt"**
我们先**ok = [计算并保存 ok](文件.存在(路径="demo.txt"))**,供下一步使用。
1. `ok`
**打印 内容="有演示文件"**
+7 -3
View File
@@ -8,11 +8,15 @@ description: 去空白、拆分、拼接(代码即文档试点)
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
导入 lib/文本。括号路径或经典点号调用均可。
**`t` = [文本.去空白] s=" marqdo "**
我们先**t = [计算并保存 t](文本.去空白(s=" marqdo "))**,供下一步使用。
**打印 内容=`t`**
**`parts` = [文本.拆分] s="甲,乙,丙" sep=","**
**`j` = [文本.拼接] xs=`parts` sep="-"**
我们先**parts = [计算并保存 parts](文本.拆分(s="甲,乙,丙", sep=","))**,供下一步使用。
我们先**j = [计算并保存 j](文本.拼接(xs=`parts`, sep="-"))**,供下一步使用。
**打印 内容=`j`**
+11 -3
View File
@@ -8,12 +8,20 @@ description: Unix 时间、格式化、解析、睡眠
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
这一页使用固定的 Unix 时间戳与固定日期文本,展示格式化和解析之间的关系。格式化得到 1970-01-01,解析得到相应秒数;它没有读取机器当前时钟。格式串使用 strftime 规则,接入其他来源时应明确原文本的时区与完整格式,不能根据看起来相似的日期就假设含义相同。
最后的零毫秒睡眠只演示调用位置,不用于测量调度精度,也不会制造实际等待。格式化、解析与睡眠有各自的效应和错误边界,按时间库契约授权即可。非法日期或格式不匹配时应保留诊断,不回退到时间戳零来掩盖失败。本页输出用于观察这两个固定值,不把打印结果写回源文件。
Unix 时间助手(lib/时间)。格式为 strftime。
**`s` = [时间.格式化] 秒=0 格式="%Y-%m-%d"**
我们先**s = [格式化给定的零时刻](时间.格式化(秒=0, 格式="%Y-%m-%d"))**,供下一步使用。
**打印 内容=`s`**
**`u` = [时间.解析时间] 内容="1970-01-01 00:00:00" 格式="%Y-%m-%d %H:%M:%S"**
我们先**u = [解析当前日期或 URL 输入](时间.解析时间(内容="1970-01-01 00:00:00", 格式="%Y-%m-%d %H:%M:%S"))**,供下一步使用。
**打印 内容=`u`**
**[时间.睡眠毫秒] 毫秒=0**
此处**[以零毫秒演示等待调用](时间.睡眠毫秒(毫秒=0))**,随后即可结束本页演示。
+8 -4
View File
@@ -8,13 +8,17 @@ description: 环境变量、dotenv、工作目录、参数、退出、执行
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
导入 lib/系统.mq.md。函数:取环境、设环境、加载环境(可选路径)、参数表、工作目录、退出(码)、执行(命令)。加载环境不覆盖已有变量。view 下退出会软失败,不结束进程。
**`d` = [系统.工作目录]**
我们先**d = [计算并保存 d](系统.工作目录())**,供下一步使用。
**`n` = [长度] 值=`d`**
我们先**n = [计算并保存 n](长度(值=`d`))**,供下一步使用。
1. `n` > 0
> 打印 内容=工作目录就绪
随后我们**[显示当前步骤的结果](> 打印 内容="工作目录就绪")**。
2. *
> 打印 内容=工作目录空
随后我们**[显示当前步骤的结果](> 打印 内容="工作目录空")**。
+6 -2
View File
@@ -8,8 +8,12 @@ description: HTTP(S) 与地址编码
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
导入 lib/网络.mq.md。函数:获取(地址)、提交(地址, 内容;可选 content_type / headers)、编码地址(内容)。支持 HTTP 与 HTTPS(ureq)。
**`e` = [网络.编码地址] 内容="你好"**
我们先**e = [计算并保存 e](网络.编码地址(内容="你好"))**,供下一步使用。
> 打印 内容=`e`
随后我们**[显示当前步骤的结果](> 打印 内容=`e`)**。
+5 -1
View File
@@ -8,6 +8,10 @@ description: 把运行结果写回入口 .mq.md
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
自写回把结果写入入口文件(你 run 的那份 .mq.md)里的 marqdo-out 注释块。
记录 内容=(record)— 默认写在调用下方;at_end=真 则在文件末尾单独一块。
@@ -16,4 +20,4 @@ description: 把运行结果写回入口 .mq.md
列表 — 列出文件中所有输出块。
> 打印 内容=自写回总览就绪
随后我们**[显示当前步骤的结果](> 打印 内容="自写回总览就绪")**。
+11 -3
View File
@@ -8,6 +8,14 @@ description: 改 / 行数 / 取行(代码即文档试点)
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
先用一列表格表示两个文本元素,再替换第一项并保存返回的新列表。集合更新是不可变操作,若忽略返回值,原变量就仍指向旧数据。改操作的路径位置从一开始,而取行的 i 从零开始;本例刻意把两者并排展示,以免读者把不同接口的索引约定混为一谈。
更新后的第一项为甲改,列表长度仍为二,取行返回同一个第一项。本例不涉及文件、插件或解释器,输入与返回均是普通 Marqdo 值。真实业务可以继续组合筛选、映射和聚合;对于嵌套记录,先明确路径中每一段是字段名还是列表位置,并让缺失路径的诊断保持可见。打印只帮助观察,不会使后续函数自动获得这些值。
嵌套写入用 表.改;读元用链接取元。
`xs` =
@@ -17,9 +25,9 @@ description: 改 / 行数 / 取行(代码即文档试点)
| 甲 |
| 乙 |
**`xs` = [表.改] 入=`xs` 于=1 值="甲改"**
**`n` = [表.行数] xs=`xs`**
**`r` = [表.取行] xs=`xs` i=0**
我们先**xs = [替换列表第一项并保留新集合](表.改(入=`xs`, 于=1, 值="甲改"))**,供下一步使用。
我们先**n = [取得本步骤需要的路径或计数](表.行数(xs=`xs`))**,供下一步使用。
我们先**r = [按零起点读取第一行](表.取行(xs=`xs`, i=0))**,供下一步使用。
**打印 内容=[1](access(xs, "1"))**
**打印 内容=`n`**