- Add read-only FunctionRef.module/name and PluginHandle.plugin/export members; PluginHandle.id stays private (ADR-0029). - Extend stdlib/format.mq.md to Formula/Code/FunctionRef/PluginHandle/ Memory/Resource/Unit, with UTF-8 byte length for Code. - Fix two-digit ordered-list body indentation so arms 10+ stay inside their branch (they were previously top-level statements). - Extend stdlib demo to Formula/Code/FunctionRef and assert all three io.写值/打印 pairs match byte-for-byte. - Add runtime member observation test, ADR-0029, spec/status/changelog/evidence. Gate: fmt, clippy -D warnings, 416 tests passed.
3.5 KiB
字节长度
(文本)
点 = text.codepoints(文本)
总字节 = 0
下标 = 0
-
下标 < 长度(点)码点 = 点[下标]
-
码点 < 128总字节 = 总字节 + 1
-
码点 < 2048总字节 = 总字节 + 2
-
码点 < 65536总字节 = 总字节 + 3
-
true总字节 = 总字节 + 4
下标 = 下标 + 1
-
总字节
显示
(值)
按语言值语义格式化,用于与内置 打印 的输出对照。
覆盖 Unit/None/Bool/Int/Float/Text/List/Map/Table/Formula/Code/
FunctionRef/PluginHandle/Memory/Resource。
类别 = 类型(值)
-
类别 == "Unit""Unit"
-
类别 == "None""None"
-
类别 == "Text"值
-
类别 == "List"列表显示(值)
-
类别 == "Map"映射显示(值)
-
类别 == "Table"表格显示(值)
-
类别 == "Formula""Formula(" + 转义文本(值.latex) + ")"
-
类别 == "Code""Code(" + 转义文本(值.language) + ", " + 文本(字节长度(值.source)) + " bytes)"
-
类别 == "FunctionRef""FunctionRef(" + 值.module + "::" + 值.name + ")"
-
类别 == "PluginHandle""PluginHandle(" + 值.plugin + "::" + 值.export + ")"
-
类别 == "Memory""Memory"
-
类别 == "Resource""Resource"
-
true文本(值)
列表显示
(列表)
结果 = "["
下标 = 0
-
下标 < 长度(列表)-
下标 > 0结果 = 结果 + ", "
-
true忽略 = 0
结果 = 结果 + 值显示(列表[下标])
下标 = 下标 + 1
-
结果 + "]"
映射显示
(映射)
键 = map.keys(映射)
结果 = "{"
下标 = 0
-
下标 < 长度(键)-
下标 > 0结果 = 结果 + ", "
-
true忽略 = 0
当前键 = 键[下标]
结果 = 结果 + 当前键 + ": " + 值显示(map.get(映射, 当前键))
下标 = 下标 + 1
-
结果 + "}"
表格显示
(表格)
列 = table.columns(表格)
结果 = "Table[" + 连接文本(列, " | ") + "]{"
行号 = 0
-
行号 < 长度(表格)-
行号 > 0结果 = 结果 + "; "
-
true忽略 = 0
行 = table.row(表格, 行号)
单元格 = []
列号 = 0
-
列号 < 长度(行)单元格 = list.append(单元格, 显示(行[列号]))
列号 = 列号 + 1
结果 = 结果 + 连接文本(单元格, " | ")
行号 = 行号 + 1
-
结果 + "}"
连接文本
(列表, 分隔)
结果 = ""
下标 = 0
-
下标 < 长度(列表)-
下标 > 0结果 = 结果 + 分隔
-
true忽略 = 0
结果 = 结果 + 列表[下标]
下标 = 下标 + 1
-
结果
值显示
(值)
列表/映射/表格内部使用 repr 语义:Text 带引号并转义,其它值递归显示。
类别 = 类型(值)
-
类别 == "Text"转义文本(值)
-
true显示(值)
转义文本
(文本)
点 = text.codepoints(文本)
结果 = "\""
下标 = 0
-
下标 < 长度(点)码点 = 点[下标]
-
码点 == 34结果 = 结果 + "\\\"" -
码点 == 92结果 = 结果 + "\\\\" -
码点 == 10结果 = 结果 + "\\n" -
码点 == 9结果 = 结果 + "\\t" -
码点 == 13结果 = 结果 + "\\r" -
true结果 = 结果 + text.from_codepoint(码点)
下标 = 下标 + 1
-
结果 + "\""