Inside italic/bold code segments every bare word is a variable — including call arguments and method-call receivers — so text literals must be quoted and receivers no longer need backticks. A bare dotted callee `a.b` resolves as a method call when `a` is a local variable, otherwise as a library path (Python-style unified namespace), in both the tree-walk and bytecode backends. Migrate ~70 tests plus ext/web, ext/quantum, ext/ai and the example projects to the new idiom; update SKILL.md and the design docs; fix the web/quantum example data model (db/index.mq.md). Unit and gold suites pass; only the 3 network-live tests fail offline. Co-authored-by: Cursor <cursoragent@cursor.com>
3.1 KiB
3.1 KiB
Objects(#)与函数(##+)
| 状态 | Accepted |
| 日期 | 2026-08-06 |
| 相关 | markdown-mapping.md · ext-llm.md |
1. 约定
| 标题层 | 含义 |
|---|---|
#(恰好一层) |
对象 / 类型。正文 = 构造体;调用类型名 = 构造实例。 |
## 及更深 |
函数(自由函数或方法)。层数差表示嵌套,与 v0.1 相同。 |
# main 是入口对象:运行文件 = 执行其构造体。若无 main,且文件恰好只有一个无参顶层 # 对象(如 # Hello World),则把它当作入口。
2. 实例句柄
构造返回值若为 map,运行时写入 _type(文本,值为类型名),形成句柄。
方法调用通过 _type 找到定义对象,再解析其下的 ## 方法。
方法体内自动绑定:
自(中文)self(英文)
二者同一接收者。
3. 调用外形
# 大模型
+ `模型名`
*自 = …配置 map…*
**自**
## 运行
+ `提示`
…使用 `自` …
**内容**
# main
*模型 = > 大模型 模型名="gpt-4o-mini"*
*回复 = > 模型.运行 提示="你好"*
> print text=`回复`
> 大模型 …— 构造> `模型`.运行 …— 方法(接收者 +.+ 方法名;独立>调用需反引号接收者`模型`;在*…*/**…**段内接收者不加反引号:*回复 = > 模型.运行 提示="你好"*)## 自由函数挂在模块顶层(非某对象子标题)— 与旧版顶层# http_get对等,现写为## http_get
4. 标准库
官方 lib/*.mq.md 以顶层自由函数为主:全部为 ##(不再使用 # 冒充类型)。
真正的类型化扩展(如 ext/llm)使用 # 类型 + ## 方法。
5. 继承(# 子类 = > 父类)
# Greeter
## hello
+ `who`
*msg = "Hello, `who`!"*
**msg**
# Loud = > Greeter
## hello
+ `who`
*msg = "HELLO, `who`!"*
**msg**
| 规则 | 说明 |
|---|---|
| 语法 | # Child = > Parent(右侧必须是 > + 简单类型名;无路径) |
_type |
构造后仍为最具体子类名 |
| 方法查找 | 先子类 ##,未命中再沿基类链;同名则子类覆盖 |
| 构造 | 不隐式调用父构造(无 auto-super)。需要父字段时在子类正文首行显式 `self` = > Parent …,再改字段并 **self**;返回 map 的 _type 仍为子类名 |
| 多继承 | 不支持 |
| 诊断 | 未知基类、循环继承、非法 RHS(如 # Foo = 1) |
6. 非目标(本波)
- 接口 / 可见性 / 多继承
- 无
_type的「鸭子」方法分发 - 用表格声明字段 schema(表格仍表示数据集合;见 tables-maps-footnotes.md)
7. 迁移摘要
| 旧 | 新 |
|---|---|
库顶层 # http_get |
## http_get |
# main + ## 嵌套 |
不变(main = 入口对象) |
ext 顶层 # complete |
# llm / # 大模型 构造 + ## complete / ## 运行 |