feat(stdlib): add table logical-value algorithms (CM-A08)

- Add stdlib/data/table.mq.md with select/filter/sort/append/set-cell/join/
  group as value-returning .mq.md functions over table.columns/row/cell.
- Keep Value::Table logical semantics, GFM AST laziness and T0 physical
  storage unchanged; no new table builtin or HostOp (ADR-0032).
- Add stdlib/tests/table.mq.md and a CLI test asserting shapes/order and
  input immutability; refresh the bundle digest.
- Update architecture/status/spec/README/changelog and evidence.

Gate: fmt, clippy -D warnings, 420 tests passed.
This commit is contained in:
cflmy committed 2026-11-20 22:28:52 +08:00
1 parent 49910ece43
commit a8e62a5ba9
12 files changed
+533 -4

No files matched your search

+1
View File
@@ -8,6 +8,7 @@ module; a mismatch is a hard error.
- `text.mq.md` — UTF-8 encoding into `Memory`
- `io.mq.md` — `写文本` / `写值` through `resource.write(stdout)`
- `demo.mq.md` — side-by-side comparison with builtin `打印`
- `data/table.mq.md` — value-returning table select/filter/sort/append/set/join/group
- `tests/` — bundle self-tests
The digest is a SHA-256 over sorted `*.mq.md` relative paths, a NUL, file
+233
View File
@@ -0,0 +1,233 @@
## 选择列
`(数据, 列)`
**列名 = table.columns(数据)**
**结果行 = []**
**行号 = 0**
- `行号 < 长度(数据)`
**行 = table.row(数据, 行号)**
**结果行 = list.append(结果行, [行[列]])**
**行号 = 行号 + 1**
*表([列名[列]], 结果行)*
## 过滤数值大于
`(数据, 列, 阈值)`
**列名 = table.columns(数据)**
**结果行 = []**
**行号 = 0**
- `行号 < 长度(数据)`
**行 = table.row(数据, 行号)**
1. `行[列] > 阈值`
**结果行 = list.append(结果行, 行)**
2. `true`
**忽略 = 0**
**行号 = 行号 + 1**
*表(列名, 结果行)*
## 插入有序
`(已排序, 行, 列)`
**新列表 = []**
**已插入 = false**
**下标 = 0**
- `下标 < 长度(已排序)`
**当前行 = 已排序[下标]**
1. `not 已插入 and 当前行[列] > 行[列]`
**新列表 = list.append(新列表, 行)**
**新列表 = list.append(新列表, 当前行)**
**已插入 = true**
2. `true`
**新列表 = list.append(新列表, 当前行)**
**下标 = 下标 + 1**
1. `not 已插入`
**新列表 = list.append(新列表, 行)**
2. `true`
**忽略 = 0**
*新列表*
## 排序
`(数据, 列)`
**列名 = table.columns(数据)**
**行数 = 长度(数据)**
**已排序 = []**
**下标 = 0**
- `下标 < 行数`
**已排序 = 插入有序(已排序, table.row(数据, 下标), 列)**
**下标 = 下标 + 1**
*表(列名, 已排序)*
## 追加行
`(数据, 行)`
**列名 = table.columns(数据)**
**所有行 = []**
**行号 = 0**
- `行号 < 长度(数据)`
**所有行 = list.append(所有行, table.row(数据, 行号))**
**行号 = 行号 + 1**
*表(列名, list.append(所有行, 行))*
## 设置单元格
`(数据, 目标行, 目标列, 值)`
**列名 = table.columns(数据)**
**新行表 = []**
**行号 = 0**
- `行号 < 长度(数据)`
**行 = table.row(数据, 行号)**
1. `行号 == 目标行`
**新行 = []**
**列号 = 0**
- `列号 < 长度(行)`
1. `列号 == 目标列`
**新行 = list.append(新行, 值)**
2. `true`
**新行 = list.append(新行, 行[列号])**
**列号 = 列号 + 1**
**新行表 = list.append(新行表, 新行)**
2. `true`
**新行表 = list.append(新行表, 行)**
**行号 = 行号 + 1**
*表(列名, 新行表)*
## 连接
`(左, 右, 左列, 右列)`
**表头 = list.concat(table.columns(左), table.columns(右))**
**结果行 = []**
**左行号 = 0**
- `左行号 < 长度(左)`
**左行 = table.row(左, 左行号)**
**键 = 左行[左列]**
**右行号 = 0**
- `右行号 < 长度(右)`
**右行 = table.row(右, 右行号)**
1. `右行[右列] == 键`
**结果行 = list.append(结果行, list.concat(左行, 右行))**
2. `true`
**忽略 = 0**
**右行号 = 右行号 + 1**
**左行号 = 左行号 + 1**
*表(表头, 结果行)*
## 分组
`(数据, 键列, 值列)`
**结果 = {}**
**行号 = 0**
- `行号 < 长度(数据)`
**行 = table.row(数据, 行号)**
**键 = 行[键列]**
**当前 = map.get(结果, 键)**
**列表 = []**
1. `map.has(结果, 键)`
**列表 = 当前**
2. `true`
**忽略 = 0**
**列表 = list.append(列表, 行[值列])**
**结果 = map.set(结果, 键, 列表)**
**行号 = 行号 + 1**
*结果*
+1 -1
View File
@@ -1,5 +1,5 @@
{
"name": "marqdo-stdlib",
"version": "0.1.0",
"digest": "sha256:9ff5342c3279f4e468129e575570befb19ea38e7dc59e1c46a35da3515480430"
"digest": "sha256:67710611a9f56b403d0ef4c295272ba95cd6fc0bee9c7314f4a42d8e54e8aba2"
}
+28
View File
@@ -0,0 +1,28 @@
---
import:
table: "std:data/table"
---
## main
**数据 = 表(["名称", "分数"], [["甲", 87], ["乙", 92], ["丙", 71]])**
**选择 = table.选择列(数据, 1)**
**过滤 = table.过滤数值大于(数据, 1, 80)**
**排序 = table.排序(数据, 1)**
**追加 = table.追加行(数据, ["丁", 65])**
**设置 = table.设置单元格(数据, 0, 1, 99)**
**左 = 表(["名称", "分数"], [["甲", 87], ["乙", 92]])**
**右 = 表(["名称", "等级"], [["乙", "A"], ["甲", "B"]])**
**连接 = table.连接(左, 右, 0, 0)**
**分组 = table.分组(表(["类别", "值"], [["a", 1], ["b", 2], ["a", 3]]), 0, 1)**
*[选择, 过滤, 排序, 追加, 设置, 连接, 分组, 数据]*