Files
marqdo-cli/examples/stdlib/format.mq.md
T
cflmy 92bfbf2568 feat(rfc-cm): baseline P0-P3 compute machine, stdlib and resource slices
Implements the first vertical slices of RFC-CM-0001/0002 on top of a113d89:

- P1: opaque Memory regions (64 KiB pages, budgets, grow-only), byte
  read/write, Memory-index place assignment, wire/host-boundary rejection.
- CM-A04/A05: value-semantics List/Map/Text/Table primitives and the
  recoverable Result map convention.
- CM-A06: opaque Resource handles, resource.open/read/write/close, stdout
  write, granted project-file read and buffered write, strict fail-closed.
- CM-A07 Compat-A: explicit .mq.md format/utf8/io chain matching builtin
  print for the covered value types; builtin remains default.
- P2 fixtures: allocators, list/tree/graph/hash, integer codecs, UTF-8
  encode/decode, CSV/JSON subsets, table filter/sort/join, bytecode VM.
- ADRs 0022-0027, spec updates, evidence reports and 68 semantic goldens.

Gate: cargo fmt --check, clippy -D warnings, 407 tests passed.
2026-11-20 21:16:54 +08:00

210 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 显示
`(值)`
按语言值语义格式化,用于与内置 `打印` 的输出对照。
当前只覆盖 Unit/None/Bool/Int/Float/Text/List/Map/Table;Formula/Code/
FunctionRef/PluginHandle 仍缺少公开观察接口。
**类别 = 类型(值)**
1. `类别 == "Unit"`
*"Unit"*
2. `类别 == "None"`
*"None"*
3. `类别 == "Text"`
*值*
4. `类别 == "List"`
*列表显示(值)*
5. `类别 == "Map"`
*映射显示(值)*
6. `类别 == "Table"`
*表格显示(值)*
7. `true`
*文本(值)*
## 列表显示
`(列表)`
**结果 = "["**
**下标 = 0**
- `下标 < 长度(列表)`
1. `下标 > 0`
**结果 = 结果 + ", "**
2. `true`
**忽略 = 0**
**结果 = 结果 + 值显示(列表[下标])**
**下标 = 下标 + 1**
*结果 + "]"*
## 映射显示
`(映射)`
**键 = map.keys(映射)**
**结果 = "{"**
**下标 = 0**
- `下标 < 长度(键)`
1. `下标 > 0`
**结果 = 结果 + ", "**
2. `true`
**忽略 = 0**
**当前键 = 键[下标]**
**结果 = 结果 + 当前键 + ": " + 值显示(map.get(映射, 当前键))**
**下标 = 下标 + 1**
*结果 + "}"*
## 表格显示
`(表格)`
**列 = table.columns(表格)**
**结果 = "Table[" + 连接文本(列, " | ") + "]{"**
**行号 = 0**
- `行号 < 长度(表格)`
1. `行号 > 0`
**结果 = 结果 + "; "**
2. `true`
**忽略 = 0**
**行 = table.row(表格, 行号)**
**单元格 = []**
**列号 = 0**
- `列号 < 长度(行)`
**单元格 = list.append(单元格, 显示(行[列号]))**
**列号 = 列号 + 1**
**结果 = 结果 + 连接文本(单元格, " | ")**
**行号 = 行号 + 1**
*结果 + "}"*
## 连接文本
`(列表, 分隔)`
**结果 = ""**
**下标 = 0**
- `下标 < 长度(列表)`
1. `下标 > 0`
**结果 = 结果 + 分隔**
2. `true`
**忽略 = 0**
**结果 = 结果 + 列表[下标]**
**下标 = 下标 + 1**
*结果*
## 值显示
`(值)`
列表/映射/表格内部使用 repr 语义:Text 带引号并转义,其它值递归显示。
**类别 = 类型(值)**
1. `类别 == "Text"`
*转义文本(值)*
2. `true`
*显示(值)*
## 转义文本
`(文本)`
**点 = text.codepoints(文本)**
**`结果 = "\""`**
**下标 = 0**
- `下标 < 长度(点)`
**码点 = 点[下标]**
1. `码点 == 34`
**`结果 = 结果 + "\\\""`**
2. `码点 == 92`
**`结果 = 结果 + "\\\\"`**
3. `码点 == 10`
**`结果 = 结果 + "\\n"`**
4. `码点 == 9`
**`结果 = 结果 + "\\t"`**
5. `码点 == 13`
**`结果 = 结果 + "\\r"`**
6. `true`
**结果 = 结果 + text.from_codepoint(码点)**
**下标 = 下标 + 1**
*`结果 + "\""`*