This commit is contained in:
cflmy committed 2026-11-18 10:51:28 +00:00
commit a4c04666b4
217 files changed
+506293

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
---
markup: occlusion
title: Standard library — overview
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.
New bytes, archive, Result, document and collection workflows retain explicit platform limits. Check one-based paths versus legacy zero-based indexes before using arrays. Real workflows live in examples/stdlib-handbook; the development guide is doc/library-development.mq.md.
Official libraries live under lib/ (alias std/). Use a nested import mapping in YAML frontmatter, for example a module alias mapped to lib/text.mq.md or lib/fs.mq.md.
English-named files export English APIs; Chinese-named files export Chinese APIs. JSON is special: only lib/json.mq.md (shared by both languages).
Importing selects the module; it does not replace effect authorization at the execution entry. Under marqdo view or static export, exit soft-fails and long sleeps are clamped so the console stays up.
Modules: text (text / 文本), table (table / 表), files (fs / 文件), time (time / 时间), system (sys / 系统), json (json only), net (net / 网络), math (math / 数学), foreign (foreign / 外联), plugin (plugin / 插件), writeback (writeback / 自写回), subtask (subtask / 子任务). Foreign v2 adds structured invoke records, JSON calls, parallel fan-out, persistent Python/Node kernels, an explicit state bridge and document-native view cells — see stdlib/foreign.mq.md and features/19-foreign-view-cells.mq.md.
From v0.1.2, official `lib/*.mq.md` is embedded in the `marqdo` binary (disk `lib/` or `MARQDO_LIB` still overrides). Standalone `.exe` works without a separate stdlib zip.
Official optional extensions live under ext/ (not stdlib): ext/llm, ext/agent — see features/05-extensions.mq.md and doc/design/ext-llm.md / ext-agent.md.
Sibling pages in this folder document each module. Chinese overview: 00-索引.mq.md.
We now **[Display this step's result](> print text="stdlib overview ok")**.
+33
View File
@@ -0,0 +1,33 @@
---
markup: occlusion
title: 标准库 — 总览
description: 如何导入官方 lib 模块
---
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
版本 2.6.0:标准库通常是单个 lib/名称.mq.md 文件,源码本身就是手册,不要求额外 index。直接阅读标题下的参数、默认值和返回表即可调用;多文件拓展库才通过 index 组织模块。当前 61 份公开标准库包含 650 个函数。
使用 YAML 的 import(或导入)映射导入模块。文件、网络、进程等副作用仍由运行入口授权;marqdo call 默认只运行纯函数,文件调用要明确 --effects 与 --fs-root。文档契约不会自动授予权限。
新增字节、归档、Result、文档操作及集合工作流;数组读写要注意一基路径与旧零基接口的区别。更完整的标准库源码在 lib/,真实工程在 examples/stdlib-handbook,开发规范见 doc/library-development.mq.md。
官方库在仓库 lib/(别名 std/)。在 YAML frontmatter 的 import 或导入映射中填写模块别名与路径,例如 lib/文本.mq.md 或 lib/文件.mq.md。
拉丁文件名导出英文 API;中文文件名导出中文 API。JSON 特例:只有 lib/json.mq.md(中英共用)。
导入只选择模块,不替代实际运行入口的副作用授权。marqdo view 或静态导出里,退出会软失败、长睡眠会被钳制,以免拖垮控制台。
模块:文本(text / 文本)、表(table / 表)、文件(fs / 文件)、时间(time / 时间)、系统(sys / 系统)、json(仅 json)、网络(net / 网络)、数学(math / 数学)、外联(foreign / 外联)、插件(plugin / 插件)、自写回(writeback / 自写回)、子任务(subtask / 子任务)。外联 v2 新增结构化执行记录、JSON 调用、并行扇出、Python/Node 持久内核、显式状态桥与文档原生 view 单元 — 见 stdlib/外联.mq.md 与 features/19-外联视图单元.mq.md。
自 v0.1.2 起,官方 `lib/*.mq.md` 内置于 `marqdo` 二进制(磁盘 `lib/` 或 `MARQDO_LIB` 仍可覆盖)。单独下载 `.exe` 即可导入标准库,无需再解压 stdlib 包。
官方可选扩展在 ext/(不是标准库):ext/llm、ext/agent — 见 features/05-扩展.mq.md。
各模块说明见本目录其它页。English: 00-overview.mq.md.
随后我们**[显示当前步骤的结果](> 打印 内容="标准库总览就绪")**。
+155
View File
@@ -0,0 +1,155 @@
---
markup: occlusion
title: lib/foreign — foreign kernels v2
description: Structured execution, JSON calls, parallel fan-out, persistent kernels and an explicit state bridge
import:
foreign: lib/foreign.mq.md
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.
---
Probe before you run.
We first **node = [Compute node](foreign.probe(lang="node"))** for the next step.
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.
---
A structured record, not just stdout.
`marker` =
```node
console.log(new Intl.NumberFormat("en-US", {style:"currency", currency:"CNY"}).format(950));
```
We first **record = [Compute record](foreign.invoke(code=`marker`))** for the next step.
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.
---
JSON in, JSON out.
`format_money` =
```node
let input = "";
process.stdin.on("data", chunk => { input += chunk; });
process.stdin.on("end", () => {
console.log(JSON.stringify(new Intl.NumberFormat("en-US", {style:"currency", currency:"CNY"}).format(JSON.parse(input))));
});
```
We first **single = [Compute single](foreign.call(code=`format_money`, input=21))** for the next step.
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.
---
Parallel fan-out.
`numbers` =
| value |
|-------|
| 1 |
| 2 |
| 3 |
| 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))**.
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.
---
A persistent kernel.
We first **session = [Compute session](foreign.session_open(lang="node"))** for the next step.
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.
We first **second = [Compute second](foreign.session_eval(id=`session`, source="money.format(21)"))** for the next step.
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`.
---
The explicit state bridge.
We **[Copy the explicit rate into the existing kernel](foreign.session_set(id=`session`, name="rate", value=0.08))**.
We first **rate = [Compute rate](foreign.session_get(id=`session`, name="rate"))** for the next step.
We now **[Display this step's result](> print text=`rate`)**.
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.
---
Cells in view.
`foreign.session` owns the document's kernel state. The kernel and cell order are ordinary tables passed as arguments; the names are free:
```text
`分析内核` =
| 名称 | 语言 | 命令 | 说明 |
|------|------|------|------|
| 分析 | node | | shared analysis |
| 复核 | node | | isolated review |
`分析单元` =
| 单元 | 内核 | 说明 |
|------|------|------|
| 准备数据 | 分析 | write state |
| 计算指标 | 分析 | read state |
| 独立复核 | 复核 | isolated kernel |
`会话` = > 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 native-first Intl workflow in [`features/19-foreign-view-cells.mq.md`](../features/19-foreign-view-cells.mq.md).
---
Safety defaults.
| Boundary | Default |
|---|---|
| Execution | requires the host execution capability |
| Shell | no shell; arguments are split explicitly |
| Output | bounded, with truncated |
| Timeout | process group killed on Unix / taskkill /T on Windows |
| 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).
+22
View File
@@ -0,0 +1,22 @@
---
markup: occlusion
title: lib/fs — files
description: Read and write text under the sandbox
import:
fs: lib/fs.mq.md
---
# 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.
We first **ok = [Compute ok](fs.exists(path="demo.txt"))** for the next step.
1. `ok`
**打印 内容="demo-present"**
2. *
**打印 内容="demo-missing"**
+23
View File
@@ -0,0 +1,23 @@
---
markup: occlusion
title: lib/json — JSON
description: Shared EN/ZH path; parse and stringify (code-as-docs pilot)
import:
json: lib/json.mq.md
---
# 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.
We first **obj = [Compute obj](json.parse(text="{}"))** for the next step.
We first **ty = [Compute ty](type(`obj`))** for the next step.
**打印 内容=`ty`**
We first **out = [Compute out](json.stringify(value=`obj`))** for the next step.
**打印 内容=`out`**
+17
View File
@@ -0,0 +1,17 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 520 360" width="520" height="360" role="img" aria-label="function plot">
<defs>
<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" fill="#4b5563"/>
</marker>
</defs>
<style>
.grid { stroke: #e5e7eb; stroke-width: 1; }
.axis { stroke: #4b5563; stroke-width: 1.5; }
.tick { stroke: #4b5563; stroke-width: 1; }
.curve { fill: none; stroke: #1f6feb; stroke-width: 2; }
.pt { fill: #1f6feb; }
.axis-label { font: 12px ui-sans-serif, system-ui, sans-serif; fill: #374151; font-weight: 600; }
.tick-label { font: 10px ui-sans-serif, system-ui, sans-serif; fill: #6b7280; }
</style>
<line x1="36.00" y1="36" x2="36.00" y2="324" class="grid"/><line x1="110.67" y1="36" x2="110.67" y2="324" class="grid"/><line x1="185.33" y1="36" x2="185.33" y2="324" class="grid"/><line x1="260.00" y1="36" x2="260.00" y2="324" class="grid"/><line x1="334.67" y1="36" x2="334.67" y2="324" class="grid"/><line x1="409.33" y1="36" x2="409.33" y2="324" class="grid"/><line x1="484.00" y1="36" x2="484.00" y2="324" class="grid"/><line x1="36" y1="310.91" x2="484" y2="310.91" class="grid"/><line x1="36" y1="252.73" x2="484" y2="252.73" class="grid"/><line x1="36" y1="194.55" x2="484" y2="194.55" class="grid"/><line x1="36" y1="136.36" x2="484" y2="136.36" class="grid"/><line x1="36" y1="78.18" x2="484" y2="78.18" class="grid"/><line x1="36" y1="252.73" x2="484" y2="252.73" class="axis" marker-end="url(#arrow)"/><line x1="260.00" y1="324" x2="260.00" y2="36" class="axis" marker-end="url(#arrow)"/><text x="488.00" y="256.73" class="axis-label">x</text><text x="266.00" y="40.00" class="axis-label">y</text><line x1="36.00" y1="248.73" x2="36.00" y2="256.73" class="tick"/><text x="36.00" y="266.73" text-anchor="middle" class="tick-label">-3</text><line x1="110.67" y1="248.73" x2="110.67" y2="256.73" class="tick"/><text x="110.67" y="266.73" text-anchor="middle" class="tick-label">-2</text><line x1="185.33" y1="248.73" x2="185.33" y2="256.73" class="tick"/><text x="185.33" y="266.73" text-anchor="middle" class="tick-label">-1</text><line x1="334.67" y1="248.73" x2="334.67" y2="256.73" class="tick"/><text x="334.67" y="266.73" text-anchor="middle" class="tick-label">1</text><line x1="409.33" y1="248.73" x2="409.33" y2="256.73" class="tick"/><text x="409.33" y="266.73" text-anchor="middle" class="tick-label">2</text><line x1="484.00" y1="248.73" x2="484.00" y2="256.73" class="tick"/><text x="484.00" y="266.73" text-anchor="middle" class="tick-label">3</text><line x1="256.00" y1="310.91" x2="264.00" y2="310.91" class="tick"/><text x="252.00" y="310.91" text-anchor="end" dominant-baseline="middle" class="tick-label">-2</text><line x1="256.00" y1="194.55" x2="264.00" y2="194.55" class="tick"/><text x="252.00" y="194.55" text-anchor="end" dominant-baseline="middle" class="tick-label">2</text><line x1="256.00" y1="136.36" x2="264.00" y2="136.36" class="tick"/><text x="252.00" y="136.36" text-anchor="end" dominant-baseline="middle" class="tick-label">4</text><line x1="256.00" y1="78.18" x2="264.00" y2="78.18" class="tick"/><text x="252.00" y="78.18" text-anchor="end" dominant-baseline="middle" class="tick-label">6</text><text x="252.00" y="266.73" class="tick-label">0</text><path d="M 36.00 49.09 L 38.24 54.30 L 40.48 59.46 L 42.72 64.56 L 44.96 69.62 L 47.20 74.62 L 49.44 79.57 L 51.68 84.46 L 53.92 89.31 L 56.16 94.10 L 58.40 98.84 L 60.64 103.52 L 62.88 108.16 L 65.12 112.74 L 67.36 117.27 L 69.60 121.75 L 71.84 126.17 L 74.08 130.54 L 76.32 134.86 L 78.56 139.13 L 80.80 143.35 L 83.04 147.51 L 85.28 151.62 L 87.52 155.68 L 89.76 159.68 L 92.00 163.64 L 94.24 167.54 L 96.48 171.39 L 98.72 175.18 L 100.96 178.93 L 103.20 182.62 L 105.44 186.26 L 107.68 189.84 L 109.92 193.38 L 112.16 196.86 L 114.40 200.29 L 116.64 203.67 L 118.88 206.99 L 121.12 210.27 L 123.36 213.49 L 125.60 216.65 L 127.84 219.77 L 130.08 222.83 L 132.32 225.84 L 134.56 228.80 L 136.80 231.71 L 139.04 234.56 L 141.28 237.36 L 143.52 240.11 L 145.76 242.81 L 148.00 245.45 L 150.24 248.05 L 152.48 250.59 L 154.72 253.07 L 156.96 255.51 L 159.20 257.89 L 161.44 260.22 L 163.68 262.50 L 165.92 264.72 L 168.16 266.90 L 170.40 269.02 L 172.64 271.09 L 174.88 273.10 L 177.12 275.07 L 179.36 276.98 L 181.60 278.84 L 183.84 280.64 L 186.08 282.40 L 188.32 284.10 L 190.56 285.75 L 192.80 287.35 L 195.04 288.89 L 197.28 290.38 L 199.52 291.82 L 201.76 293.21 L 204.00 294.55 L 206.24 295.83 L 208.48 297.06 L 210.72 298.24 L 212.96 299.36 L 215.20 300.44 L 217.44 301.46 L 219.68 302.43 L 221.92 303.34 L 224.16 304.21 L 226.40 305.02 L 228.64 305.78 L 230.88 306.48 L 233.12 307.14 L 235.36 307.74 L 237.60 308.29 L 239.84 308.79 L 242.08 309.23 L 244.32 309.63 L 246.56 309.97 L 248.80 310.25 L 251.04 310.49 L 253.28 310.67 L 255.52 310.80 L 257.76 310.88 L 260.00 310.91 L 262.24 310.88 L 264.48 310.80 L 266.72 310.67 L 268.96 310.49 L 271.20 310.25 L 273.44 309.97 L 275.68 309.63 L 277.92 309.23 L 280.16 308.79 L 282.40 308.29 L 284.64 307.74 L 286.88 307.14 L 289.12 306.48 L 291.36 305.78 L 293.60 305.02 L 295.84 304.21 L 298.08 303.34 L 300.32 302.43 L 302.56 301.46 L 304.80 300.44 L 307.04 299.36 L 309.28 298.24 L 311.52 297.06 L 313.76 295.83 L 316.00 294.55 L 318.24 293.21 L 320.48 291.82 L 322.72 290.38 L 324.96 288.89 L 327.20 287.35 L 329.44 285.75 L 331.68 284.10 L 333.92 282.40 L 336.16 280.64 L 338.40 278.84 L 340.64 276.98 L 342.88 275.07 L 345.12 273.10 L 347.36 271.09 L 349.60 269.02 L 351.84 266.90 L 354.08 264.72 L 356.32 262.50 L 358.56 260.22 L 360.80 257.89 L 363.04 255.51 L 365.28 253.07 L 367.52 250.59 L 369.76 248.05 L 372.00 245.45 L 374.24 242.81 Line truncated
</svg>

After

Width:  |  Height:  |  Size: 6.4 KiB

+44
View File
@@ -0,0 +1,44 @@
---
markup: occlusion
title: lib/math — numbers, formulas, plots
description: High-school math stdlib (English)
import:
math: lib/math.mq.md
---
# 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` =
$$
x^2 - 2
$$
Numeric helpers: pi, e, num, add/sub/mul/div/pow, sin/cos/tan, sqrt/abs/ln/exp, floor/ceil, min/max. Random: seed, random, random_int (reproducible after seed).
Symbolic: formula(text), simplify, expand, diff, subs, eval, solve.
Plotting (already in the library): plot / plot_points / plot_conic return SVG text. Axes include arrows and tick labels; grid is on by default (pass grid=False / grid=假 to hide). Optional path= writes a file under the sandbox. With no path, CLI auto-writes stem-plot-n.svg and prints plot: …; view embeds the SVG under Execution.
diff / simplify / expand / partial subs return formula values so you can chain (e.g. differentiate twice, then plot or eval).
We first **ty = [Compute ty](type(`f`))** for the next step.
We now **[Display this step's result](> print text=`ty`)**.
We first **df = [Compute df](math.diff(formula=`f`, var="x"))** for the next step.
We now **[Display this step's result](> print text=`df`)**.
We first **roots = [Compute roots](math.solve(formula=`f`, var="x"))** for the next step.
We now **[Display this step's result](> print text=`roots`)**.
We first **_svg = [Compute _svg](math.plot(formula=`f`, var="x", min=-3, max=3))** for the next step.
We now **[Display this step's result](> print text="plot-ok")**.
+19
View File
@@ -0,0 +1,19 @@
---
markup: occlusion
title: lib/net — HTTP(S)
description: Minimal HTTP(S) client and URL encode
import:
net: lib/net.mq.md
---
# 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`).
We first **e = [Compute e](net.url_encode(text="hello world"))** for the next step.
We now **[Display this step's result](> print text=`e`)**.
+24
View File
@@ -0,0 +1,24 @@
---
markup: occlusion
title: lib/plugin — native ABI
description: Load optional shared libraries (.dll / .so / .dylib)
import:
plugin: lib/plugin.mq.md
---
# 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).
We first **names = [Compute names](plugin.list())** for the next step.
We first **n = [Compute n](len(`names`))** for the next step.
1. `n` >= 0
We now **[Display this step's result](> print text="plugin-ok")**.
2. *
We now **[Display this step's result](> print text="plugin-bad")**.
+27
View File
@@ -0,0 +1,27 @@
---
markup: occlusion
title: lib/subtask — concurrent tasks
description: Spawn file, function, or foreign code in parallel
import:
subtask: lib/subtask.mq.md
---
# 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.
fn= plus optional args= runs a function in a thread; wait returns the return value.
code= runs a foreign fence subprocess; wait returns stdout text.
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.
We now **[Display this step's result](> print text="subtask overview ok")**.
+24
View File
@@ -0,0 +1,24 @@
---
markup: occlusion
title: lib/sys — process
description: Env, dotenv, cwd, args, exit, exec
import:
sys: lib/sys.mq.md
---
# 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.
We first **d = [Compute d](sys.cwd())** for the next step.
We first **n = [Compute n](len(`d`))** for the next step.
1. `n` > 0
We now **[Display this step's result](> print text="cwd-ok")**.
2. *
We now **[Display this step's result](> print text="cwd-empty")**.
+32
View File
@@ -0,0 +1,32 @@
---
markup: occlusion
title: lib/table — collections
description: put, append, and map helpers (code-as-docs pilot)
import:
table: lib/table.mq.md
---
# 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.
We first **h = [Compute h](table.put(in=None, at="Authorization", value="Bearer-demo"))** for the next step.
`xs` =
| v |
|---|
| a |
| b |
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"))**
**打印 内容=`n`**
+22
View File
@@ -0,0 +1,22 @@
---
markup: occlusion
title: lib/text — strings
description: Trim, split, join (code-as-docs pilot)
import:
text: lib/text.mq.md
---
# 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.
We first **t = [Compute t](text.str_trim(s=" marqdo "))** for the next step.
**打印 内容=`t`**
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`**
+23
View File
@@ -0,0 +1,23 @@
---
markup: occlusion
title: lib/time — clock
description: Unix time, format, parse, sleep
import:
time: lib/time.mq.md
---
# 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.
We first **s = [Compute s](time.format(unix=0, pattern="%Y-%m-%d"))** for the next step.
**打印 内容=`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**
+23
View File
@@ -0,0 +1,23 @@
---
markup: occlusion
title: lib/writeback — Jupyter-style writeback
description: Persist run output in the entry .mq.md file
import:
writeback: lib/writeback.mq.md
---
# 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.
get / clear — read or remove the adjacent block (or EOF block when at_end=true).
list — all output blocks in the entry file.
We now **[Display this step's result](> print text="writeback overview ok")**.
+155
View File
@@ -0,0 +1,155 @@
---
markup: occlusion
title: lib/外联 — 外联内核 v2
description: 结构化执行、JSON 调用、并行扇出、持久内核与显式状态桥
导入:
外联: lib/外联.mq.md
stdin: 21
---
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
`lib/外联` 用本机解释器运行代码围栏和内联源码。v2 不改 Markdown 表面,新增结构化记录、JSON 进出、并行扇出、Python/Node 持久内核和显式状态桥。
文件仍然是一篇文档:绑定的代码围栏是可读的 Markdown,`外联.*` 把它变成可执行单元。
---
先探测,再运行。
我们先**node = [计算并保存 node](外联.探测(语言="node"))**,供下一步使用。
随后我们**[显示当前步骤的结果](> 打印 内容=[ok](access(`node`, "ok")))**。
随后我们**[显示当前步骤的结果](> 打印 内容=[version](access(`node`, "version")))**。
`探测` 返回 `{lang, cmd, path, ok, version, error}`。省略语言时探测所有已知语言。
---
结构化记录,而不只是 stdout。
`标记` =
```node
console.log(new Intl.NumberFormat("zh-CN", {style:"currency", currency:"CNY"}).format(950));
```
我们先**记录 = [计算并保存 记录](外联.执行(代码=`标记`))**,供下一步使用。
随后我们**[显示当前步骤的结果](> 打印 内容=[ok](access(`记录`, "ok")))**。
随后我们**[显示当前步骤的结果](> 打印 内容=[stdout](access(`记录`, "stdout")))**。
随后我们**[显示当前步骤的结果](> 打印 内容=[code](access(`记录`, "code")))**。
`执行` 在进程失败时不抛错,而是在一条记录里给出 `ok`、`code`、`stdout`、`stderr`、`ms`、`timed_out`、`truncated`、`result` 与 `error`。
---
JSON 进,JSON 出。
`金额格式` =
```node
let input = "";
process.stdin.on("data", chunk => { input += chunk; });
process.stdin.on("end", () => {
console.log(JSON.stringify(new Intl.NumberFormat("zh-CN", {style:"currency", currency:"CNY"}).format(JSON.parse(input))));
});
```
我们先**单个 = [计算并保存 单个](外联.调用(代码=`金额格式`, 输入=21))**,供下一步使用。
随后我们**[显示当前步骤的结果](> 打印 内容=`单个`)**。
输入编码成 JSON 写到 stdin;stdout 的最后一个值再解析成 JSON。想同时保留原始记录时,用 `执行` 的 `输出="json"`。
---
并行扇出。
`数值表` =
| 数值 |
|------|
| 1 |
| 2 |
| 3 |
| 4 |
这张单列绑定表本身就是原生数值列表,可以直接交给批量调用。
随后我们**格式列表 = [并行展示金额并保持输入顺序](外联.批量调用(代码=`金额格式`, 输入表=`数值表`, 并发=4))**。
随后我们**[显示当前步骤的结果](> 打印 内容=`格式列表`)**。
`批量调用` 对每个输入独立运行同一程序,保持输入顺序并返回解析后的 JSON 列表;`批量运行` 对完整 invoke 选项表做同样的事。
---
持久内核。
我们先**会话 = [计算并保存 会话](外联.会话开启(语言="node"))**,供下一步使用。
我们先**第一次 = [计算并保存 第一次](外联.会话求值(标识=`会话`, 源码="var money = new Intl.NumberFormat(\"zh-CN\", {style:\"currency\", currency:\"CNY\"});"))**,供下一步使用。
我们先**第二次 = [计算并保存 第二次](外联.会话求值(标识=`会话`, 源码="money.format(21)"))**,供下一步使用。
随后我们**[显示当前步骤的结果](> 打印 内容=[result](access(`第二次`, "result")))**。
第一次求值创建的变量会保留到第二次。内核不是 shell:用 `会话求值`、`会话取值`、`会话变量`,最后 `会话关闭`。
---
显式状态桥。
我们**[将明确选定的值复制进已有内核](外联.会话设值(标识=`会话`, 名称="rate", 值=0.08))**。
我们先**利率 = [计算并保存 利率](外联.会话取值(标识=`会话`, 名称="rate"))**,供下一步使用。
随后我们**[显示当前步骤的结果](> 打印 内容=`利率`)**。
读回所需结果后,我们**[关闭本次持久展示内核](外联.会话关闭(标识=`会话`))**。
这是 JSON 拷贝,不是共享内存:内核收到一个值,Marqdo 取回一个值。没有隐式镜像,也没有隐藏的全局命名空间。
---
view 中的单元。
`foreign.session` 拥有文档的内核状态。内核和单元顺序都是作为参数传入的普通表格,名字可以自由选择:
```text
`分析内核` =
| 名称 | 语言 | 命令 | 说明 |
|------|------|------|------|
| 分析 | node | | 共享分析 |
| 复核 | node | | 独立复核 |
`分析单元` =
| 单元 | 内核 | 说明 |
|------|------|------|
| 准备数据 | 分析 | 写入状态 |
| 计算指标 | 分析 | 读取状态 |
| 独立复核 | 复核 | 隔离内核 |
`会话` = > foreign.session kernels=`分析内核` cells=`分析单元`
```
`view` 消费 `会话` 句柄,提供 Run All、Step、切换内核、journal 和单元状态。没有 `会话` 时,view 的 cells 是无状态的一次性运行:同一套外壳,但没有持久内核。没有第二个 CLI 模式。原生分析与 Intl 示例见 [`features/19-外联视图单元.mq.md`](../features/19-外联视图单元.mq.md)。
---
安全默认值。
| 边界 | 默认 |
|---|---|
| 执行 | 需要宿主执行能力 |
| Shell | 不经过 shell;参数显式切分 |
| 输出 | 有界,带 truncated |
| 超时 | Unix 杀进程组 / Windows taskkill /T |
| 工作目录 | 文件沙箱根目录;不隐式越界 |
| 并行 | 扇出有上限;每个任务隔离 |
完整 API 见 [../../lib/外联.mq.md](../../lib/外联.mq.md),设计见 [../../doc/design/foreign-kernel.md](../../doc/design/foreign-kernel.md)。
+27
View File
@@ -0,0 +1,27 @@
---
markup: occlusion
title: lib/子任务 — 并发子任务
description: 文件、函数或外联代码并行执行
导入:
子任务: lib/子任务.mq.md
---
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
启动(spawn)四选一(其余参数默认 None)。
路径=:marqdo run 子进程;等待返回退出码。
函数= 加可选 参数=:入口模块中的函数(线程);等待返回返回值。
代码=:外联代码块子进程;等待返回 stdout 文本。
语言= 加 源码=:外联源码子进程;等待返回 stdout 文本。
文件子任务默认静默;静默=假 时继承父终端。另有:探测、终止、等待全部。父进程结束会终止文件/外联子进程。
随后我们**[显示当前步骤的结果](> 打印 内容="子任务总览就绪")**。
+24
View File
@@ -0,0 +1,24 @@
---
markup: occlusion
title: lib/插件 — 原生 ABI
description: 加载可选共享库(.dll / .so / .dylib)
导入:
插件: lib/插件.mq.md
---
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
导入 lib/插件.mq.md。函数:加载(路径)、卸载()、列出()。加载后,插件注册的名称可像普通函数一样调用。C 契约见 include/marqdo_abi.h 与 doc/design/ext-abi.md。路径须落在程序沙箱内。
我们先**names = [计算并保存 names](插件.列出())**,供下一步使用。
我们先**n = [计算并保存 n](长度(值=`names`))**,供下一步使用。
1. `n` >= 0
随后我们**[显示当前步骤的结果](> 打印 内容="插件就绪")**。
2. *
随后我们**[显示当前步骤的结果](> 打印 内容="插件异常")**。
+17
View File
@@ -0,0 +1,17 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 520 360" width="520" height="360" role="img" aria-label="function plot">
<defs>
<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" fill="#4b5563"/>
</marker>
</defs>
<style>
.grid { stroke: #e5e7eb; stroke-width: 1; }
.axis { stroke: #4b5563; stroke-width: 1.5; }
.tick { stroke: #4b5563; stroke-width: 1; }
.curve { fill: none; stroke: #1f6feb; stroke-width: 2; }
.pt { fill: #1f6feb; }
.axis-label { font: 12px ui-sans-serif, system-ui, sans-serif; fill: #374151; font-weight: 600; }
.tick-label { font: 10px ui-sans-serif, system-ui, sans-serif; fill: #6b7280; }
</style>
<line x1="36.00" y1="36" x2="36.00" y2="324" class="grid"/><line x1="110.67" y1="36" x2="110.67" y2="324" class="grid"/><line x1="185.33" y1="36" x2="185.33" y2="324" class="grid"/><line x1="260.00" y1="36" x2="260.00" y2="324" class="grid"/><line x1="334.67" y1="36" x2="334.67" y2="324" class="grid"/><line x1="409.33" y1="36" x2="409.33" y2="324" class="grid"/><line x1="484.00" y1="36" x2="484.00" y2="324" class="grid"/><line x1="36" y1="310.91" x2="484" y2="310.91" class="grid"/><line x1="36" y1="252.73" x2="484" y2="252.73" class="grid"/><line x1="36" y1="194.55" x2="484" y2="194.55" class="grid"/><line x1="36" y1="136.36" x2="484" y2="136.36" class="grid"/><line x1="36" y1="78.18" x2="484" y2="78.18" class="grid"/><line x1="36" y1="252.73" x2="484" y2="252.73" class="axis" marker-end="url(#arrow)"/><line x1="260.00" y1="324" x2="260.00" y2="36" class="axis" marker-end="url(#arrow)"/><text x="488.00" y="256.73" class="axis-label">x</text><text x="266.00" y="40.00" class="axis-label">y</text><line x1="36.00" y1="248.73" x2="36.00" y2="256.73" class="tick"/><text x="36.00" y="266.73" text-anchor="middle" class="tick-label">-3</text><line x1="110.67" y1="248.73" x2="110.67" y2="256.73" class="tick"/><text x="110.67" y="266.73" text-anchor="middle" class="tick-label">-2</text><line x1="185.33" y1="248.73" x2="185.33" y2="256.73" class="tick"/><text x="185.33" y="266.73" text-anchor="middle" class="tick-label">-1</text><line x1="334.67" y1="248.73" x2="334.67" y2="256.73" class="tick"/><text x="334.67" y="266.73" text-anchor="middle" class="tick-label">1</text><line x1="409.33" y1="248.73" x2="409.33" y2="256.73" class="tick"/><text x="409.33" y="266.73" text-anchor="middle" class="tick-label">2</text><line x1="484.00" y1="248.73" x2="484.00" y2="256.73" class="tick"/><text x="484.00" y="266.73" text-anchor="middle" class="tick-label">3</text><line x1="256.00" y1="310.91" x2="264.00" y2="310.91" class="tick"/><text x="252.00" y="310.91" text-anchor="end" dominant-baseline="middle" class="tick-label">-2</text><line x1="256.00" y1="194.55" x2="264.00" y2="194.55" class="tick"/><text x="252.00" y="194.55" text-anchor="end" dominant-baseline="middle" class="tick-label">2</text><line x1="256.00" y1="136.36" x2="264.00" y2="136.36" class="tick"/><text x="252.00" y="136.36" text-anchor="end" dominant-baseline="middle" class="tick-label">4</text><line x1="256.00" y1="78.18" x2="264.00" y2="78.18" class="tick"/><text x="252.00" y="78.18" text-anchor="end" dominant-baseline="middle" class="tick-label">6</text><text x="252.00" y="266.73" class="tick-label">0</text><path d="M 36.00 49.09 L 38.24 54.30 L 40.48 59.46 L 42.72 64.56 L 44.96 69.62 L 47.20 74.62 L 49.44 79.57 L 51.68 84.46 L 53.92 89.31 L 56.16 94.10 L 58.40 98.84 L 60.64 103.52 L 62.88 108.16 L 65.12 112.74 L 67.36 117.27 L 69.60 121.75 L 71.84 126.17 L 74.08 130.54 L 76.32 134.86 L 78.56 139.13 L 80.80 143.35 L 83.04 147.51 L 85.28 151.62 L 87.52 155.68 L 89.76 159.68 L 92.00 163.64 L 94.24 167.54 L 96.48 171.39 L 98.72 175.18 L 100.96 178.93 L 103.20 182.62 L 105.44 186.26 L 107.68 189.84 L 109.92 193.38 L 112.16 196.86 L 114.40 200.29 L 116.64 203.67 L 118.88 206.99 L 121.12 210.27 L 123.36 213.49 L 125.60 216.65 L 127.84 219.77 L 130.08 222.83 L 132.32 225.84 L 134.56 228.80 L 136.80 231.71 L 139.04 234.56 L 141.28 237.36 L 143.52 240.11 L 145.76 242.81 L 148.00 245.45 L 150.24 248.05 L 152.48 250.59 L 154.72 253.07 L 156.96 255.51 L 159.20 257.89 L 161.44 260.22 L 163.68 262.50 L 165.92 264.72 L 168.16 266.90 L 170.40 269.02 L 172.64 271.09 L 174.88 273.10 L 177.12 275.07 L 179.36 276.98 L 181.60 278.84 L 183.84 280.64 L 186.08 282.40 L 188.32 284.10 L 190.56 285.75 L 192.80 287.35 L 195.04 288.89 L 197.28 290.38 L 199.52 291.82 L 201.76 293.21 L 204.00 294.55 L 206.24 295.83 L 208.48 297.06 L 210.72 298.24 L 212.96 299.36 L 215.20 300.44 L 217.44 301.46 L 219.68 302.43 L 221.92 303.34 L 224.16 304.21 L 226.40 305.02 L 228.64 305.78 L 230.88 306.48 L 233.12 307.14 L 235.36 307.74 L 237.60 308.29 L 239.84 308.79 L 242.08 309.23 L 244.32 309.63 L 246.56 309.97 L 248.80 310.25 L 251.04 310.49 L 253.28 310.67 L 255.52 310.80 L 257.76 310.88 L 260.00 310.91 L 262.24 310.88 L 264.48 310.80 L 266.72 310.67 L 268.96 310.49 L 271.20 310.25 L 273.44 309.97 L 275.68 309.63 L 277.92 309.23 L 280.16 308.79 L 282.40 308.29 L 284.64 307.74 L 286.88 307.14 L 289.12 306.48 L 291.36 305.78 L 293.60 305.02 L 295.84 304.21 L 298.08 303.34 L 300.32 302.43 L 302.56 301.46 L 304.80 300.44 L 307.04 299.36 L 309.28 298.24 L 311.52 297.06 L 313.76 295.83 L 316.00 294.55 L 318.24 293.21 L 320.48 291.82 L 322.72 290.38 L 324.96 288.89 L 327.20 287.35 L 329.44 285.75 L 331.68 284.10 L 333.92 282.40 L 336.16 280.64 L 338.40 278.84 L 340.64 276.98 L 342.88 275.07 L 345.12 273.10 L 347.36 271.09 L 349.60 269.02 L 351.84 266.90 L 354.08 264.72 L 356.32 262.50 L 358.56 260.22 L 360.80 257.89 L 363.04 255.51 L 365.28 253.07 L 367.52 250.59 L 369.76 248.05 L 372.00 245.45 L 374.24 242.81 Line truncated
</svg>

After

Width:  |  Height:  |  Size: 6.4 KiB

+44
View File
@@ -0,0 +1,44 @@
---
markup: occlusion
title: lib/数学 — 数值、公式、作图
description: 高中数学标准库(中文)
导入:
数学: lib/数学.mq.md
---
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
导入 lib/数学.mq.md。运行时类型:num(浮点)与 formula(符号树)。用空 RHS 赋值后跟 `$$…$$` 围栏绑定公式(与表格赋值同构)。view 的 Structure 会用 KaTeX 渲染该公式。
`f` =
$$
x^2 - 2
$$
数值:圆周率、自然底数、数、加/减/乘/除/幂、正弦/余弦/正切、平方根/绝对值/对数/指数、向下取整/向上取整、最小/最大。随机:设种子、随机、随机整数。
符号:公式、化简、展开、求导、代入、求值、求解。
作图(库已提供):绘图 / 绘点列 / 绘圆锥,返回 SVG 文本。坐标轴带箭头与刻度;*默认显示网格*(`grid=假` 可关闭)。可选 path= 写盘。无 path 时 CLI 自动写 stem-plot-n.svg 并打印 plot: …;view 在 Execution 内嵌 SVG。
求导 / 化简 / 展开 / 未完全数值化的代入仍返回 formula,可继续链式调用(例如求二阶导后再绘图或求值)。
我们先**ty = [计算并保存 ty](type(`f`))**,供下一步使用。
随后我们**[显示当前步骤的结果](> print text=`ty`)**。
我们先**df = [计算并保存 df](数学.求导(formula=`f`, var="x"))**,供下一步使用。
随后我们**[显示当前步骤的结果](> print text=`df`)**。
我们先**roots = [计算并保存 roots](数学.求解(formula=`f`, var="x"))**,供下一步使用。
随后我们**[显示当前步骤的结果](> print text=`roots`)**。
我们先**_svg = [计算并保存 _svg](数学.绘图(formula=`f`, var="x", min=-3, max=3))**,供下一步使用。
随后我们**[显示当前步骤的结果](> print text="plot-ok")**。
+22
View File
@@ -0,0 +1,22 @@
---
markup: occlusion
title: lib/文件 — 文件系统
description: 沙箱内读写文本
导入:
文件: lib/文件.mq.md
---
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
文件系统助手(lib/文件)。裸路径不要写斜杠(会被当成除法)。可用同目录文件名或变量。
我们先**ok = [计算并保存 ok](文件.存在(路径="demo.txt"))**,供下一步使用。
1. `ok`
**打印 内容="有演示文件"**
2. *
**打印 内容="无演示文件"**
+22
View File
@@ -0,0 +1,22 @@
---
markup: occlusion
title: lib/文本 — 字符串
description: 去空白、拆分、拼接(代码即文档试点)
导入:
文本: lib/文本.mq.md
---
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
导入 lib/文本。括号路径或经典点号调用均可。
我们先**t = [计算并保存 t](文本.去空白(s=" marqdo "))**,供下一步使用。
**打印 内容=`t`**
我们先**parts = [计算并保存 parts](文本.拆分(s="甲,乙,丙", sep=","))**,供下一步使用。
我们先**j = [计算并保存 j](文本.拼接(xs=`parts`, sep="-"))**,供下一步使用。
**打印 内容=`j`**
+27
View File
@@ -0,0 +1,27 @@
---
markup: occlusion
title: lib/时间 — 时钟
description: Unix 时间、格式化、解析、睡眠
导入:
时间: lib/时间.mq.md
---
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
这一页使用固定的 Unix 时间戳与固定日期文本,展示格式化和解析之间的关系。格式化得到 1970-01-01,解析得到相应秒数;它没有读取机器当前时钟。格式串使用 strftime 规则,接入其他来源时应明确原文本的时区与完整格式,不能根据看起来相似的日期就假设含义相同。
最后的零毫秒睡眠只演示调用位置,不用于测量调度精度,也不会制造实际等待。格式化、解析与睡眠有各自的效应和错误边界,按时间库契约授权即可。非法日期或格式不匹配时应保留诊断,不回退到时间戳零来掩盖失败。本页输出用于观察这两个固定值,不把打印结果写回源文件。
Unix 时间助手(lib/时间)。格式为 strftime。
我们先**s = [格式化给定的零时刻](时间.格式化(秒=0, 格式="%Y-%m-%d"))**,供下一步使用。
**打印 内容=`s`**
我们先**u = [解析当前日期或 URL 输入](时间.解析时间(内容="1970-01-01 00:00:00", 格式="%Y-%m-%d %H:%M:%S"))**,供下一步使用。
**打印 内容=`u`**
此处**[以零毫秒演示等待调用](时间.睡眠毫秒(毫秒=0))**,随后即可结束本页演示。
+24
View File
@@ -0,0 +1,24 @@
---
markup: occlusion
title: lib/系统 — 进程
description: 环境变量、dotenv、工作目录、参数、退出、执行
导入:
系统: lib/系统.mq.md
---
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
导入 lib/系统.mq.md。函数:取环境、设环境、加载环境(可选路径)、参数表、工作目录、退出(码)、执行(命令)。加载环境不覆盖已有变量。view 下退出会软失败,不结束进程。
我们先**d = [计算并保存 d](系统.工作目录())**,供下一步使用。
我们先**n = [计算并保存 n](长度(值=`d`))**,供下一步使用。
1. `n` > 0
随后我们**[显示当前步骤的结果](> 打印 内容="工作目录就绪")**。
2. *
随后我们**[显示当前步骤的结果](> 打印 内容="工作目录空")**。
+19
View File
@@ -0,0 +1,19 @@
---
markup: occlusion
title: lib/网络 — HTTP
description: HTTP(S) 与地址编码
导入:
网络: lib/网络.mq.md
---
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
导入 lib/网络.mq.md。函数:获取(地址)、提交(地址, 内容;可选 content_type / headers)、编码地址(内容)。支持 HTTP 与 HTTPS(ureq)。
我们先**e = [计算并保存 e](网络.编码地址(内容="你好"))**,供下一步使用。
随后我们**[显示当前步骤的结果](> 打印 内容=`e`)**。
+23
View File
@@ -0,0 +1,23 @@
---
markup: occlusion
title: lib/自写回 — Jupyter 式写回
description: 把运行结果写回入口 .mq.md
导入:
自写回: lib/自写回.mq.md
---
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
自写回把结果写入入口文件(你 run 的那份 .mq.md)里的 marqdo-out 注释块。
记录 内容=(record)— 默认写在调用下方;at_end=真 则在文件末尾单独一块。
读取 / 清除 — 读或删相邻块(at_end 时指 EOF 块)。
列表 — 列出文件中所有输出块。
随后我们**[显示当前步骤的结果](> 打印 内容="自写回总览就绪")**。
+34
View File
@@ -0,0 +1,34 @@
---
markup: occlusion
title: lib/表 — 列表与字典
description: 改 / 行数 / 取行(代码即文档试点)
导入:
表: lib/表.mq.md
---
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
先用一列表格表示两个文本元素,再替换第一项并保存返回的新列表。集合更新是不可变操作,若忽略返回值,原变量就仍指向旧数据。改操作的路径位置从一开始,而取行的 i 从零开始;本例刻意把两者并排展示,以免读者把不同接口的索引约定混为一谈。
更新后的第一项为甲改,列表长度仍为二,取行返回同一个第一项。本例不涉及文件、插件或解释器,输入与返回均是普通 Marqdo 值。真实业务可以继续组合筛选、映射和聚合;对于嵌套记录,先明确路径中每一段是字段名还是列表位置,并让缺失路径的诊断保持可见。打印只帮助观察,不会使后续函数自动获得这些值。
嵌套写入用 表.改;读元用链接取元。
`xs` =
| v |
|---|
| 甲 |
| 乙 |
我们先**xs = [替换列表第一项并保留新集合](表.改(入=`xs`, 于=1, 值="甲改"))**,供下一步使用。
我们先**n = [取得本步骤需要的路径或计数](表.行数(xs=`xs`))**,供下一步使用。
我们先**r = [按零起点读取第一行](表.取行(xs=`xs`, i=0))**,供下一步使用。
**打印 内容=[1](access(xs, "1"))**
**打印 内容=`n`**
**打印 内容=`r`**