From 53bc3538da8c9f01b3990894b2a70e30d58ff4d9 Mon Sep 17 00:00:00 2001 From: cflmy Date: Mon, 14 Sep 2026 11:38:24 +0800 Subject: [PATCH] docs(lib): narrate table/text/json as code-as-docs pilot Add purpose lines and bracket-call examples in EN/ZH libs and public/stdlib demos; keep explicit + params so function-body prose cannot be mistaken for link-index or bold code. Co-authored-by: Cursor --- doc/design/lib-code-as-docs.md | 6 ++- doc/design/stdlib-table.md | 9 ++-- doc/roadmap/lib-ext-code-as-docs.md | 3 +- lib/json.mq.md | 20 ++++++- lib/table.mq.md | 82 ++++++++++++++++++++++------- lib/text.mq.md | 28 ++++++++-- lib/文本.mq.md | 26 ++++++++- lib/表.mq.md | 80 ++++++++++++++++++++++------ public/stdlib/json.mq.md | 18 +++---- public/stdlib/table.mq.md | 15 +++--- public/stdlib/text.mq.md | 13 ++--- public/stdlib/文本.mq.md | 13 ++--- public/stdlib/表.mq.md | 14 ++--- 13 files changed, 238 insertions(+), 89 deletions(-) diff --git a/doc/design/lib-code-as-docs.md b/doc/design/lib-code-as-docs.md index 0fcc952..f24568d 100644 --- a/doc/design/lib-code-as-docs.md +++ b/doc/design/lib-code-as-docs.md @@ -38,9 +38,11 @@ | 要 | 不要 | |----|------| | GFM 表作数据;`table.put` / 具名助手 | `json.set` 链当字典构造器 | -| `[k](c)` 取元;`- [项](集合)` foreach | 新代码写 `` m[^k] `` | +| 作者程序用 `[k](c)` 取元;`- [项](集合)` foreach | 新代码写 `` m[^k] `` | | 中英 API 对称(见 [stdlib-i18n.md](stdlib-i18n.md)) | 只改一侧 | -| 一例跑通即文档 | 另开第二套「文档站」手写说明 | +| 一例跑通即文档(public/stdlib 或 examples) | 另开第二套「文档站」手写说明 | + +**库函数体内的叙述坑:** 函数体里的链接形 `[k](c)`、以及单独的 `**强调**` 会被当成可执行代码。库内说明用「链接取元 / link-index」等字面描述;可执行示例放在 `public/stdlib` 或 `examples/`,不要写在 `##` 体内当叙述。 ## 4. 波次 diff --git a/doc/design/stdlib-table.md b/doc/design/stdlib-table.md index 59ef670..129ff18 100644 --- a/doc/design/stdlib-table.md +++ b/doc/design/stdlib-table.md @@ -11,9 +11,9 @@ | 读 | 写 | |----|----| -| 脚注 `` `xs`[^1] `` / `` `m`[^key] `` / 嵌套 `` `m`[^a][^1] `` | **`table.put` / `表.改`** | +| 链接取元 `[key](xs)` / `[key](m)` / 嵌套 `[1]([a](m))`(脚注 `` `m`[^k] `` 仍兼容) | **`table.put` / `表.改`** | -`put` / `改` 的 `at=`(`于=`)与脚注同构:文本键、**1-based** 整数下标,或键/下标组成的路径列表。 +`put` / `改` 的 `at=`(`于=`)与取元同构:文本键、**1-based** 整数下标,或键/下标组成的路径列表。 ```markdown --- @@ -22,7 +22,7 @@ import table:lib/table.mq.md # main -*`h` = > table.put in=None at=Authorization value=Bearer-x* +**`h` = [table.put] in=None at="Authorization" value="Bearer-x"** `xs` = @@ -31,7 +31,8 @@ import table:lib/table.mq.md | a | | b | -*`xs` = > table.put in=`xs` at=1 value=A* +**`xs` = [table.put] in=`xs` at=1 value="A"** +**打印 内容=[Authorization](h)** ``` `in=None` 且 `at=` 为单个文本键 → 新建单键字典。值一律不可变更新(返回新集合)。 diff --git a/doc/roadmap/lib-ext-code-as-docs.md b/doc/roadmap/lib-ext-code-as-docs.md index f60a98d..17d3150 100644 --- a/doc/roadmap/lib-ext-code-as-docs.md +++ b/doc/roadmap/lib-ext-code-as-docs.md @@ -23,7 +23,7 @@ |----|------|------| | **Call** | `pre_modifiers`;`tests/structure/bracket-call.mq.md`;mapping / call-arguments | **done** | | **M0 View** | `InterpPart::Index` → `[k](base)`;`call_display` 修饰表面 | **done** | -| **M1** | 试点 `lib/table` · `lib/text` · `lib/json`(中英)+ public/stdlib 摘录 | pending | +| **M1** | 试点 `lib/table` · `lib/text` · `lib/json`(中英)+ public/stdlib | **done** | | **M2** | 其余 `lib/*` 叙述化;禁新脚注取元 | pending | | **M3–M4** | `ext/web`、`ext/ai`:脚注→链接取元;叙述;示例可逐步换括号调用 | pending | | **M5** | quantum / linalg + full gold | pending | @@ -39,3 +39,4 @@ | 日期 | 说明 | |------|------| | 2026-09-14 | 初稿;Call + M0 标 done | +| 2026-09-14 | M1 试点 table/text/json + public/stdlib 标 done | diff --git a/lib/json.mq.md b/lib/json.mq.md index a5e12fe..380012c 100644 --- a/lib/json.mq.md +++ b/lib/json.mq.md @@ -1,33 +1,47 @@ --- title: lib/json -description: JSON parse/stringify (shared EN/ZH import) +description: JSON parse/stringify (shared EN/ZH import). Not a dict builder — use lib/table. --- +Parse and stringify JSON. For maps/lists prefer GFM tables and lib/table put; do not chain json.set / json.append in new code. + ## parse + `text` +Parse JSON text into a Marqdo value. + +Caller: [json.parse] text="{}" + *> host_json_parse text=`text`* ## stringify + `value` + `indent`=None +Serialize value to JSON text; optional indent. + *> host_json_stringify value=`value` indent=`indent`* ## get + `value` + `key` +Shallow get from JSON object value at key. Prefer link-index get or table.get in new code. + *> host_json_get value=`value` key=`key`* ## keys + `value` +Keys of JSON object value. + *> host_json_keys value=`value`* ## quote + `text` +JSON-quote string text (for building request bodies). + *> host_json_quote text=`text`* ## set @@ -35,10 +49,14 @@ description: JSON parse/stringify (shared EN/ZH import) + `key` + `value` +Compatibility shallow set. Prefer table.put / table.set. + *> host_map_set map=`map` key=`key` value=`value`* ## append + `list` + `item` +Compatibility append. Prefer table.append. + *> host_list_append list=`list` item=`item`* diff --git a/lib/table.mq.md b/lib/table.mq.md index 20e70e2..4538531 100644 --- a/lib/table.mq.md +++ b/lib/table.mq.md @@ -1,34 +1,44 @@ --- title: lib/table description: >- - List and map helpers. Prefer put (1-based path, same as footnotes); at/set_at/slice - are 0-based. json is for parse/stringify. + List and map helpers. Prefer put (1-based path, same nesting as link-index get); + at/set_at/slice are 0-based. Use lib/json only for parse/stringify. --- +List and map helpers. Prefer put for nested writes; authors should read with link-index get, not new footnote indexes. + ## put + `in` + `at` + `value` -Directly update one element. `at=` is a text key, a 1-based list index, or a list path of keys/indices (same nesting as footnotes). +Update one element of collection in at path at to value. + +at is a text key, a 1-based list index, or a list of keys/indices (same nesting as link-index get). + +Caller: [table.put] in=None at="Authorization" value="Bearer-x" *> host_collection_put in=`in` at=`at` value=`value`* ## len + `xs` +Length of list or map xs. + *> len `xs`* ## rows + `xs` +Row count for list xs (alias of len). + *> len `xs`* ## at + `xs` + `i` -Index is zero-based (same as builtin `at`). Out of range → `None`. +Zero-based index into xs at i (same as builtin at). Out of range → None. *> at value=`xs` index=`i`* @@ -36,24 +46,32 @@ Index is zero-based (same as builtin `at`). Out of range → `None`. + `xs` + `i` +Zero-based row from xs at i. + *> at value=`xs` index=`i`* ## append + `list` + `item` +Append item to list. + *> host_list_append list=`list` item=`item`* ## prepend + `list` + `item` +Prepend item to list. + *> host_list_prepend list=`list` item=`item`* ## concat + `a` + `b` +Concatenate lists a and b. + *> host_list_concat a=`a` b=`b`* ## insert @@ -61,7 +79,7 @@ Index is zero-based (same as builtin `at`). Out of range → `None`. + `index` + `item` -Index is zero-based (may insert at `len` to append). +Insert item into list at zero-based index (may insert at len to append). *> host_list_insert list=`list` index=`index` item=`item`* @@ -70,7 +88,7 @@ Index is zero-based (may insert at `len` to append). + `index` + `item` -Zero-based replace. Prefer `put` with 1-based index for author-facing edits. +Zero-based replace of list at index with item. Prefer put with a 1-based index for author-facing edits. *> host_list_set_at list=`list` index=`index` item=`item`* @@ -78,12 +96,14 @@ Zero-based replace. Prefer `put` with 1-based index for author-facing edits. + `list` + `index` +Remove zero-based index from list. + *> host_list_remove_at list=`list` index=`index`* ## pop + `list` -Drop the last item (errors if empty). Use `last` first when you need the removed value. +Drop the last item of list (errors if empty). Use last first when you need the removed value. **`n` = > len `list`** 1. `n` > 0 @@ -94,11 +114,15 @@ Drop the last item (errors if empty). Use `last` first when you need the removed ## first + `list` +First item of list. + *> host_list_first list=`list`* ## last + `list` +Last item of list. + *> host_list_last list=`list`* ## slice @@ -106,7 +130,7 @@ Drop the last item (errors if empty). Use `last` first when you need the removed + `start` + `end`=None -Zero-based half-open range from `start` to `end`. +Zero-based half-open slice of list from start to end. *> host_list_slice list=`list` start=`start` end=`end`* @@ -114,25 +138,29 @@ Zero-based half-open range from `start` to `end`. + `list` + `item` +Whether list contains item. + *> host_list_contains list=`list` item=`item`* ## index_of + `list` + `item` -Zero-based index or `None`. +Zero-based index of item in list, or None. *> host_list_index_of list=`list` item=`item`* ## reverse + `list` +Reverse list. + *> host_list_reverse list=`list`* ## sort + `list` -Ascending sort (int/num/text preferred). +Ascending sort of list (int/num/text preferred). *> host_list_sort list=`list`* @@ -140,14 +168,14 @@ Ascending sort (int/num/text preferred). + `list` + `key` -Sort a list of maps by `key`. +Sort a list of maps by field key. *> host_list_sort_by list=`list` key=`key`* ## unique + `list` -Stable unique (first wins). +Stable unique of list (first wins). *> host_list_unique list=`list`* @@ -155,27 +183,29 @@ Stable unique (first wins). + `list` + `size` +Split list into chunks of size. + *> host_list_chunk list=`list` size=`size`* ## zip + `a` + `b` -Pairs until the shorter list ends. +Pair lists a and b until the shorter ends. *> host_list_zip a=`a` b=`b`* ## flatten + `list` -One-level flatten. +One-level flatten of list. *> host_list_flatten list=`list`* ## clear + `value` -Empty list or empty map (by type). +Empty list or empty map for value (by type). *> host_collection_clear value=`value`* @@ -183,7 +213,7 @@ Empty list or empty map (by type). + `map` + `key` -Missing key → `None`. +Shallow get from map at key. Missing → None. Prefer link-index get in author code. *> host_map_get map=`map` key=`key`* @@ -192,7 +222,7 @@ Missing key → `None`. + `key` + `value` -Shallow map update. Prefer `put` for nested paths. +Shallow map update. Prefer put for nested paths. *> host_map_set map=`map` key=`key` value=`value`* @@ -200,28 +230,36 @@ Shallow map update. Prefer `put` for nested paths. + `map` + `key` +Delete key from map. + *> host_map_delete map=`map` key=`key`* ## has + `map` + `key` +Whether map has key. + *> host_map_has map=`map` key=`key`* ## keys + `map` +Keys of map. + *> host_map_keys map=`map`* ## values + `map` +Values of map. + *> host_map_values map=`map`* ## items + `map` -Rows shaped as key/value maps. +Key/value rows from map. *> host_map_items map=`map`* @@ -229,19 +267,25 @@ Rows shaped as key/value maps. + `a` + `b` -Right-hand keys win. +Merge maps a and b (right-hand keys win). *> host_map_merge a=`a` b=`b`* ## size + `map` +Key count of map. + *> host_map_size map=`map`* ## empty_list +Empty list. + *> host_list_concat a=None b=None* ## empty_map +Empty map. + *> host_map_merge a=None b=None* diff --git a/lib/text.mq.md b/lib/text.mq.md index f6865ed..8bbbb5d 100644 --- a/lib/text.mq.md +++ b/lib/text.mq.md @@ -1,41 +1,57 @@ --- title: lib/text -description: Text helpers (Mid M4 thicken). Literal replace — use lib/re for regex. +description: Text helpers (Mid M4). Literal replace — use lib/re for regex. --- +Small text helpers. Prefer these over hand-rolled splits; regex belongs in lib/re. + ## str_trim + `s` +Trim ends of string s. + *> trim `s`* ## str_split + `s` + `sep` +Split string s on separator sep. + *> split value=`s` sep=`sep`* ## str_join + `xs` + `sep` +Join list xs with separator sep. + *> join value=`xs` sep=`sep`* ## contains + `text` + `sub` +Whether text contains substring sub. + +Caller: [text.contains] text="hello" sub="ell" + *> host_text_contains text=`text` sub=`sub`* ## starts_with + `text` + `prefix` +Whether text starts with prefix. + *> host_text_starts_with text=`text` prefix=`prefix`* ## ends_with + `text` + `suffix` +Whether text ends with suffix. + *> host_text_ends_with text=`text` suffix=`suffix`* ## replace @@ -44,24 +60,30 @@ description: Text helpers (Mid M4 thicken). Literal replace — use lib/re for r + `new` + `count`=None -Literal substring replace (`count` optional). +Literal replace in text: replace old with new, optional count. *> host_text_replace text=`text` old=`old` new=`new` count=`count`* ## to_upper + `text` +Uppercase text. + *> host_text_to_upper text=`text`* ## to_lower + `text` +Lowercase text. + *> host_text_to_lower text=`text`* ## repeat + `text` + `n` +Repeat text n times. + *> host_text_repeat text=`text` n=`n`* ## pad @@ -70,6 +92,6 @@ Literal substring replace (`count` optional). + `fill`=None + `align`=None -align: left (default), right, or center. +Pad text to width with fill and align (left / right / center). *> host_text_pad text=`text` width=`width` fill=`fill` align=`align`* diff --git a/lib/文本.mq.md b/lib/文本.mq.md index d593580..8d5b546 100644 --- a/lib/文本.mq.md +++ b/lib/文本.mq.md @@ -3,39 +3,55 @@ title: lib/文本 description: 文本库加厚(中层 M4)。字面替换 — 正则请用 lib/正则。 --- +常用文本助手。手写拆分不如走这里;正则请用 lib/正则。 + ## 去空白 + `s` +去掉字符串 s 两端空白。 + *> trim `s`* ## 拆分 + `s` + `sep` +按分隔符 sep 拆分字符串 s。 + *> split value=`s` sep=`sep`* ## 拼接 + `xs` + `sep` +用分隔符 sep 拼接列表 xs。 + *> join value=`xs` sep=`sep`* ## 包含 + `内容` + `子串` +内容是否包含子串。 + +调用例:[文本.包含] 内容="你好" 子串="好" + *> host_text_contains text=`内容` sub=`子串`* ## 开头是 + `内容` + `前缀` +内容是否以前缀开头。 + *> host_text_starts_with text=`内容` prefix=`前缀`* ## 结尾是 + `内容` + `后缀` +内容是否以后缀结尾。 + *> host_text_ends_with text=`内容` suffix=`后缀`* ## 替换 @@ -44,24 +60,30 @@ description: 文本库加厚(中层 M4)。字面替换 — 正则请用 lib/ + `新` + `次数`=None -字面子串替换(可选 `次数`)。 +在内容里把字面旧换成新,可选次数。 *> host_text_replace text=`内容` old=`旧` new=`新` count=`次数`* ## 大写 + `内容` +内容转大写。 + *> host_text_to_upper text=`内容`* ## 小写 + `内容` +内容转小写。 + *> host_text_to_lower text=`内容`* ## 重复 + `内容` + `次数` +把内容重复次数遍。 + *> host_text_repeat text=`内容` n=`次数`* ## 填充 @@ -70,6 +92,6 @@ description: 文本库加厚(中层 M4)。字面替换 — 正则请用 lib/ + `填充符`=None + `对齐`=None -对齐:left(默认)/ right / center。 +把内容填充到宽度,可选填充符与对齐(left / right / center)。 *> host_text_pad text=`内容` width=`宽度` fill=`填充符` align=`对齐`* diff --git a/lib/表.mq.md b/lib/表.mq.md index 6c17adb..dad0d1f 100644 --- a/lib/表.mq.md +++ b/lib/表.mq.md @@ -1,34 +1,44 @@ --- title: lib/表 description: >- - 列表与字典。优先用「改」(路径 1-based,与脚注同构);取/改位/切片为 0-based。 + 列表与字典。优先用「改」(路径 1-based,与链接取元同构);取/改位/切片为 0-based。 json 只管解析/序列化。 --- +列表与字典。嵌套写入优先「改」;作者程序里读元用链接取元,不要新写脚注取元。 + ## 改 + `入` + `于` + `值` -直接改某一元。`于=` 为文本键、1-based 下标,或键/下标组成的路径列表(与脚注嵌套同构)。 +把集合入在路径于上的那一元改成值。 + +于可以是文本键、1-based 下标,或键/下标组成的路径列表(与链接取元嵌套同构)。 + +调用例:[表.改] 入=None 于="Authorization" 值="Bearer-x" *> host_collection_put in=`入` at=`于` value=`值`* ## 长度 + `xs` +列表或字典 xs 的长度。 + *> len `xs`* ## 行数 + `xs` +列表 xs 的行数(同长度)。 + *> len `xs`* ## 取 + `xs` + `i` -下标从零起(与内置 `at` 相同)。越界 → `None`。 +从零起取 xs 的第 i 项(与内置 at 相同)。越界 → None。 *> at value=`xs` index=`i`* @@ -36,24 +46,32 @@ description: >- + `xs` + `i` +从零起取 xs 的第 i 行。 + *> at value=`xs` index=`i`* ## 追加 + `list` + `item` +在 list 末尾追加 item。 + *> host_list_append list=`list` item=`item`* ## 前插 + `list` + `item` +在 list 开头插入 item。 + *> host_list_prepend list=`list` item=`item`* ## 拼接 + `a` + `b` +拼接列表 a 与 b。 + *> host_list_concat a=`a` b=`b`* ## 插入 @@ -61,7 +79,7 @@ description: >- + `index` + `item` -下标从零起。 +在 list 的从零起 index 处插入 item。 *> host_list_insert list=`list` index=`index` item=`item`* @@ -70,7 +88,7 @@ description: >- + `index` + `item` -从零起替换;日常嵌套改写请用「改」。 +从零起替换 list 的 index 为 item;日常嵌套改写请用「改」。 *> host_list_set_at list=`list` index=`index` item=`item`* @@ -78,12 +96,14 @@ description: >- + `list` + `index` +删去 list 从零起的 index。 + *> host_list_remove_at list=`list` index=`index`* ## 弹出 + `list` -去掉末项(空表报错)。需要末值时先「末」。 +去掉 list 末项(空表报错)。需要末值时先「末」。 **`n` = > len `list`** 1. `n` > 0 @@ -94,11 +114,15 @@ description: >- ## 首 + `list` +list 的首项。 + *> host_list_first list=`list`* ## 末 + `list` +list 的末项。 + *> host_list_last list=`list`* ## 切片 @@ -106,7 +130,7 @@ description: >- + `start` + `end`=None -从零起的半开区间,从 `start` 到 `end`。 +对 list 做从零起的半开切片,从 start 到 end。 *> host_list_slice list=`list` start=`start` end=`end`* @@ -114,25 +138,29 @@ description: >- + `list` + `item` +list 是否含有 item。 + *> host_list_contains list=`list` item=`item`* ## 下标 + `list` + `item` -从零起的下标;没有 → `None`。 +item 在 list 中从零起的下标;没有 → None。 *> host_list_index_of list=`list` item=`item`* ## 反转 + `list` +反转 list。 + *> host_list_reverse list=`list`* ## 排序 + `list` -升序(优先 int/num/text)。 +对 list 升序排序(优先 int/num/text)。 *> host_list_sort list=`list`* @@ -140,14 +168,14 @@ description: >- + `list` + `key` -对 map 列表按键排序。 +对 map 列表 list 按字段 key 排序。 *> host_list_sort_by list=`list` key=`key`* ## 去重 + `list` -保序去重(保留首次)。 +对 list 保序去重(保留首次)。 *> host_list_unique list=`list`* @@ -155,33 +183,37 @@ description: >- + `list` + `size` +把 list 按 size 分块。 + *> host_list_chunk list=`list` size=`size`* ## 拉链 + `a` + `b` -取较短长度配对。 +将 a 与 b 配对,取较短长度。 *> host_list_zip a=`a` b=`b`* ## 展平 + `list` -一层展平。 +对 list 做一层展平。 *> host_list_flatten list=`list`* ## 清空 + `value` +按类型清空 value(空列表或空字典)。 + *> host_collection_clear value=`value`* ## 取键 + `map` + `key` -缺键 → `None`。 +浅取 map 的 key;缺键 → None。作者侧优先链接取元。 *> host_map_get map=`map` key=`key`* @@ -190,7 +222,7 @@ description: >- + `key` + `value` -浅层设键;嵌套请用「改」。 +浅设 map 的 key 为 value;嵌套请用「改」。 *> host_map_set map=`map` key=`key` value=`value`* @@ -198,28 +230,36 @@ description: >- + `map` + `key` +从 map 删除 key。 + *> host_map_delete map=`map` key=`key`* ## 有键 + `map` + `key` +map 是否有 key。 + *> host_map_has map=`map` key=`key`* ## 键表 + `map` +map 的键表。 + *> host_map_keys map=`map`* ## 值表 + `map` +map 的值表。 + *> host_map_values map=`map`* ## 项表 + `map` -键值对行表。 +map 的键值对行表。 *> host_map_items map=`map`* @@ -227,19 +267,25 @@ description: >- + `a` + `b` -右侧覆盖左侧。 +合并 a 与 b(右侧覆盖左侧)。 *> host_map_merge a=`a` b=`b`* ## 键数 + `map` +map 的键数。 + *> host_map_size map=`map`* ## 空表 +空列表。 + *> host_list_concat a=None b=None* ## 空字典 +空字典。 + *> host_map_merge a=None b=None* diff --git a/public/stdlib/json.mq.md b/public/stdlib/json.mq.md index 77fbcac..0835f34 100644 --- a/public/stdlib/json.mq.md +++ b/public/stdlib/json.mq.md @@ -1,19 +1,17 @@ --- title: lib/json — JSON -description: Shared EN/ZH path; parse and stringify +description: Shared EN/ZH path; parse and stringify (code-as-docs pilot) import json:lib/json.mq.md --- # main -Import lib/json.mq.md from both English and Chinese docs (no translated twin). Functions: parse(text), stringify(value), get(value, key), keys(value), quote(text) — JSON string literal with quotes (for building request bodies). Objects become the map runtime type. +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="{}"** +**`obj` = [json.parse] text="{}"** +**`ty` = > type `obj`** +**打印 内容=`ty`** -**`ty` = > type `obj` ** - -> print text=`ty` - -**`out` = > json.stringify value=`obj` ** - -> print text=`out` +**`out` = > json.stringify value=`obj`** +**打印 内容=`out`** diff --git a/public/stdlib/table.mq.md b/public/stdlib/table.mq.md index eb91554..ede8584 100644 --- a/public/stdlib/table.mq.md +++ b/public/stdlib/table.mq.md @@ -1,14 +1,15 @@ --- title: lib/table — collections -description: put, append, and map helpers +description: put, append, and map helpers (code-as-docs pilot) import table:lib/table.mq.md --- # main -Prefer `table.put` for element updates (`at=` text key, 1-based int, or list path). Use `json` for parse/stringify only. +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"** +**`h` = [table.put] in=None at="Authorization" value="Bearer-demo"** `xs` = @@ -17,9 +18,9 @@ Prefer `table.put` for element updates (`at=` text key, 1-based int, or list pat | a | | b | -**`xs` = > table.put in=`xs` at=1 value="A"** +**`xs` = [table.put] in=`xs` at=1 value="A"** **`n` = > table.rows xs=`xs`** -> print text=`h`[^Authorization] -> print text=`xs`[^1] -> print text=`n` +**打印 内容=[Authorization](h)** +**打印 内容=[1](xs)** +**打印 内容=`n`** diff --git a/public/stdlib/text.mq.md b/public/stdlib/text.mq.md index 995ed42..8295d2f 100644 --- a/public/stdlib/text.mq.md +++ b/public/stdlib/text.mq.md @@ -1,19 +1,16 @@ --- title: lib/text — strings -description: Trim, split, join wrappers +description: Trim, split, join (code-as-docs pilot) import text:lib/text.mq.md --- # main -Import lib/text.mq.md. Functions: str_trim(s), str_split(s, sep), str_join(xs, sep). +Import lib/text. Bracket path or classic dotted calls both work. -**`t` = > text.str_trim s=" marqdo "** - -> print text=`t` +**`t` = [text.str_trim] s=" marqdo "** +**打印 内容=`t`** **`parts` = > text.str_split s="a,b,c" sep=","** - **`j` = > text.str_join xs=`parts` sep="-"** - -> print text=`j` +**打印 内容=`j`** diff --git a/public/stdlib/文本.mq.md b/public/stdlib/文本.mq.md index d89203f..d3998d6 100644 --- a/public/stdlib/文本.mq.md +++ b/public/stdlib/文本.mq.md @@ -1,19 +1,16 @@ --- title: lib/文本 — 字符串 -description: 去空白、拆分、拼接 +description: 去空白、拆分、拼接(代码即文档试点) 导入 文本:lib/文本.mq.md --- # main -导入 lib/文本.mq.md。函数:去空白(s)、拆分(s, sep)、拼接(xs, sep)。 +导入 lib/文本。括号路径或经典点号调用均可。 -**`t` = > 文本.去空白 s=" marqdo "** - -> 打印 内容=`t` +**`t` = [文本.去空白] s=" marqdo "** +**打印 内容=`t`** **`parts` = > 文本.拆分 s="甲,乙,丙" sep=","** - **`j` = > 文本.拼接 xs=`parts` sep="-"** - -> 打印 内容=`j` +**打印 内容=`j`** diff --git a/public/stdlib/表.mq.md b/public/stdlib/表.mq.md index d257721..ec815d5 100644 --- a/public/stdlib/表.mq.md +++ b/public/stdlib/表.mq.md @@ -1,12 +1,12 @@ --- -title: lib/表 — 列表 -description: 行数与取行 +title: lib/表 — 列表与字典 +description: 改 / 行数 / 取行(代码即文档试点) 导入 表:lib/表.mq.md --- # main -导入 lib/表.mq.md。函数:行数(xs)、取行(xs, i)。单列表在运行时是列表。 +嵌套写入用 表.改;读元用链接取元。 `xs` = @@ -15,10 +15,10 @@ description: 行数与取行 | 甲 | | 乙 | +**`xs` = [表.改] 入=`xs` 于=1 值="甲改"** **`n` = > 表.行数 xs=`xs`** - -> 打印 内容=`n` - **`r` = > 表.取行 xs=`xs` i=0** -> 打印 内容=`r` +**打印 内容=[1](xs)** +**打印 内容=`n`** +**打印 内容=`r`**