diff --git a/.cursor/skills/marqdo/examples.md b/.cursor/skills/marqdo/examples.md index 35c622d..dd1e8a6 100644 --- a/.cursor/skills/marqdo/examples.md +++ b/.cursor/skills/marqdo/examples.md @@ -1,5 +1,7 @@ # Marqdo examples (AI) +v0.3: `**…**` = code (assign / call); `*…*` = return. Prefer `[key](coll)` over footnote get. Bracket calls: `礼貌 [问候] x`. + ## 1. Hello (English) ```markdown @@ -16,7 +18,7 @@ > 打印 内容=你好,世界! ``` -## 3. Function + named call + body end +## 3. Function + named call + empty return ```markdown # main @@ -30,22 +32,24 @@ Greeting via a nested function: > print text=Hello, `who`! ---- +*None* ``` +Or end with a whole-line empty bold return: `**` / `****`. Lone `---` is a thematic break (skipped), not function end. + ## 4. Bindings and return ```markdown # main -*a = 2* -*b = > add_one n=`a`* -> print text=`b` +**a = 2** +**b = add_one n=`a`** +**打印 内容=`b`** ## add_one + `n` -**n + 1** +*n + 1* ``` ## 5. Branch with else @@ -53,7 +57,7 @@ Greeting via a nested function: ```markdown # main -*n = 0* +**n = 0** 1. `n` > 0 > print text=positive @@ -78,8 +82,7 @@ Greeting via a nested function: > print text=`果` ``` - -## 6b. Map table + footnote get +## 6b. Map table + link-index get ```markdown # main @@ -90,13 +93,20 @@ Greeting via a nested function: |------|------| | 水果 | 蔬菜 | -*种 = 分类[^苹果]* -> print text=`种` +**种 = [苹果](分类)** +**打印 内容=`种`** -*第一 = 篮子[^1]* +`篮子` = + +| 果 | +|----| +| 苹果 | + +**第一 = [1](篮子)** +**打印 内容=`第一`** ``` -One column → list; ≥2 columns + one data row → map; ≥2 columns + many rows → map of lists. Data cells are expressions (same as call-arg values): bare words, numbers, `` `var` ``, quoted strings; URLs and `gpt-4o-mini` stay text via path/hyphen folding. Footnotes: lists use 1-based digit indices; maps use key text (including digit keys like `[^00]`). Foreach on a map walks **keys**. +One column → list; ≥2 columns + one data row → map; ≥2 columns + many rows → map of lists. Prefer `[key](coll)` (lists are 1-based). Legacy `` coll[^key] `` still parses. Foreach on a map walks **keys**. Row-oriented records (SQL-like): first header `@` / `行` / `row` → list of maps (marker column excluded): @@ -107,10 +117,27 @@ Row-oriented records (SQL-like): first header `@` / `行` / `row` → list of ma |----|------|------| | 1 | 苹果 | 2 | -*名 = 订单[^1][^品名]* +**名 = [品名]([1](订单))** ``` -## 6c. Browser effects — tables + lib/browser (not json.set) +## 6c. Bracket-marked call + modifiers + +```markdown +# main + +**打印 内容=(礼貌 [问候] "Marqdo")** + +## 问候 + + `谁` + + `礼貌`=False + +**出 = `礼貌` + ", " + `谁` + "!"** +*出* +``` + +`礼貌 [问候] …` → `礼貌=True`. `]` immediately followed by `(` is index, not a call. + +## 6d. Browser effects — tables + lib/browser (not json.set) ```markdown --- @@ -128,8 +155,8 @@ import browser:lib/browser.mq.md **`wire`** ## bump -*`count` = count + 1* -*`label` = > str count* +**count = count + 1** +**label = str count** **> browser.set_text sel="#count" text=label** ``` @@ -145,8 +172,8 @@ import text:lib/text.mq.md # main -*parts = > split value=a,b,c sep=,* -> print text=`parts` +**parts = [text.str_split] s="a,b,c" sep=","** +**打印 内容=`parts`** ``` ## 7b. Mid M1 — regex + encoding (no plugin) @@ -159,10 +186,10 @@ import enc:lib/encoding.mq.md # main -*`ok` = > re.is_match text="a@b.c" pattern="@"* -*`b64` = > enc.base64_encode text="hi"* -> print text=`ok` -> print text=`b64` +**`ok` = [re.is_match] text="a@b.c" pattern="@"** +**`b64` = [enc.base64_encode] text="hi"** +**打印 内容=`ok`** +**打印 内容=`b64`** ``` ## 7c. Mid M6 — log + uuid @@ -178,8 +205,8 @@ import uuid:lib/uuid.mq.md > log.info text="start" > log.set_level level="debug" > log.debug text="detail" -*id = > uuid.v4* -> print text=`id` +**id = [uuid.v4]** +**打印 内容=`id`** ``` ## 8. Comment paragraphs (blank-line rule) @@ -188,7 +215,7 @@ import uuid:lib/uuid.mq.md # main This whole paragraph is a comment, including lines that look like code: -*not_executed = 1* +**not_executed = 1** > print text=also still comment After a blank line, code runs: @@ -206,13 +233,13 @@ import math:lib/math.mq.md # main -*t = > num value=3.5* -> print text=`t` +**t = > num value=3.5** +**打印 内容=`t`** ``` ## 10. Object handle + method -See `tests/structure/object-handle.mq.md` and `ext/llm.mq.md`: `# Type` constructs a map with `_type`; methods use `` > `obj`.method `` and read `self` / `自`. +See `tests/structure/object-handle.mq.md` and `ext/ai/llm.mq.md`: `# Type` constructs a map with `_type`; methods use `` > `obj`.method `` and read `self` / `自`. ## 10b. Object inheritance @@ -222,16 +249,16 @@ See `tests/structure/object-handle.mq.md` and `ext/llm.mq.md`: `# Type` construc ## hello + `who` -*msg = "Hello, `who`!"* -**msg** +**msg = "Hello, `who`!"** +*msg* # Loud = > Greeter ## hello + `who` -*msg = "HELLO, `who`!"* -**msg** +**msg = "HELLO, `who`!"** +*msg* ``` `_type` stays the most specific name (`Loud`). Methods walk the base chain; same-name `##` on the child overrides. **No implicit super** — if the child needs parent fields, call the parent explicitly: @@ -240,9 +267,9 @@ See `tests/structure/object-handle.mq.md` and `ext/llm.mq.md`: `# Type` construc # Child = > Parent + `name` -*self = > Parent name=`name`* -*self = > json.set map=`self` key=extra value=1* -**self** +**self = > Parent name=`name`** +**self = [table.put] in=`self` at="extra" value=1** +*self* ``` ## 11. Agent layout (ABI) @@ -256,9 +283,9 @@ import agent:ext/agent.mq.md > load_native -*ws = > agent* -*n = > `ws`.ensure_layout* -> print text=`n` +**ws = > agent** +**n = > `ws`.ensure_layout** +**打印 内容=`n`** ``` Requires `MARQDO_AGENT_PLUGIN` pointing at the built `agent` shared library (see `doc/design/ext-agent.md`). @@ -266,14 +293,14 @@ Requires `MARQDO_AGENT_PLUGIN` pointing at the built `agent` shared library (see ## 12. What not to emit ```markdown -# BAD — bold is return, not print +# BAD — bare bold that is not code-shaped (decorative OK); do not use bold/italic as print **Hello** # BAD — Python control keywords if x > 0: print(x) -# BAD — wrapping a call in italics +# BAD — wrapping a call in italics as if it were a statement *> print text=hi* # BAD — old branch syntax (removed) @@ -290,6 +317,10 @@ if x > 0: > print text=y-pos 2. * > print text=y-other + +# GOOD — print / return +**打印 内容="hi"** +*n + 1* ``` ## 13. Dynamic site (ext/web, minimal) @@ -316,14 +347,14 @@ import db:db/index.mq.md | title | posts.title | | | body | posts.summary | | -*store = > db.open* -*css = "body{font-family:sans-serif}"* -*page = > web.page title="Hello"* -*page = > page.compose_components components=`shell`* -*page = > page.compose_main main=`main`* -*page = > page.css css=`css`* -*app = > web.app page=`page` port=8080* -*app = > app.static prefix="/static" dir="static"* +**store = > db.open** +**css = "body{font-family:sans-serif}"** +**page = > web.page title="Hello"** +**page = > page.compose_components components=`shell`** +**page = > page.compose_main main=`main`** +**page = > page.css css=`css`** +**app = > web.app page=`page` port=8080** +**app = > app.static prefix="/static" dir="static"** > listen app=`app` ``` @@ -347,13 +378,13 @@ import quantum:ext/quantum/quantum.mq.md | 1 | H | 0 | | 2 | CX | 0,1 | -*qc = > quantum.circuit qubits=2 steps=`steps`* -*rho = > `qc`.density* -*red = > `rho`.partial_trace keep=0* -*sch = > `qc`.schmidt cut=1* -*_ = > `qc`.draw kind="circuit" theme="dark"* -*_ = > `qc`.draw kind="hinton"* -> print text=`red` +**qc = > quantum.circuit qubits=2 steps=`steps`** +**rho = > `qc`.density** +**red = > `rho`.partial_trace keep=0** +**sch = > `qc`.schmidt cut=1** +**_ = > `qc`.draw kind="circuit" theme="dark"** +**_ = > `qc`.draw kind="hinton"** +**打印 内容=`red`** ``` - Full lab: `examples/quantum-entanglement/`. Bell-only: `examples/quantum-bell/`. @@ -369,19 +400,18 @@ import la:ext/linalg/linalg.mq.md # main -*`A` = > la.symbol name="A" rows=2 cols=2* -*`B` = > la.symbol name="B" rows=2 cols=2* -*`C` = `A` + `B`* -*`P` = `A` * `B`* -*`s` = > `P`.T.simplify* +**`A` = > la.symbol name="A" rows=2 cols=2** +**`B` = > la.symbol name="B" rows=2 cols=2** +**`C` = `A` + `B`** +**`P` = `A` * `B`** ``` Prefer: ```markdown -*`env` = > la.declare table=`shapes`* -*`P` = env[^A] * env[^B]* -*`t` = > `P`.T_ascii* +**`env` = > la.declare table=`shapes`** +**`P` = [A](env) * [B](env)** +**`t` = > `P`.T_ascii** ``` - Infix `+` / `-` / `*`;`ascii` / `T_ascii` 默认化简(`raw=True` 可关)。 diff --git a/doc/roadmap/lib-ext-code-as-docs.md b/doc/roadmap/lib-ext-code-as-docs.md index dfa7190..1c3fc4a 100644 --- a/doc/roadmap/lib-ext-code-as-docs.md +++ b/doc/roadmap/lib-ext-code-as-docs.md @@ -29,6 +29,7 @@ | **M5** | quantum / linalg + full gold | **done** | | **M6** | examples + public/structure + tests/ext·lib 链接取元;cafe 括号调用例 | **done** | | **M7** | structure collection 金样改链接形;public/stdlib 括号调用例 | **done** | +| **M8** | 教程第 9 章 + Skill examples → 链接取元 / v0.3 标记 | **done** | ## 2. 验收(出门) @@ -36,6 +37,7 @@ - 试点库可读:目的句 + 叙述形参 + 一例 + 短实现。 - `cargo test --test gold` 绿。 - 脚注取元金样(`tests/structure/footnote*`)仍保留作兼容门禁。 +- 教程与 Skill 示例以链接取元 / `**` 代码 / `*` 返回为准。 ## 3. 修订历史 @@ -48,3 +50,4 @@ | 2026-09-14 | M5 quantum/linalg 叙述 + public/features 取元 | | 2026-09-14 | M6 examples/public/tests 批量链接取元 + cafe 括号调用 | | 2026-09-14 | M7 structure collection 金样 + stdlib 括号调用例 | +| 2026-09-14 | M8 教程 + Skill examples 同步 | diff --git a/doc/tutorial/08-循环.md b/doc/tutorial/08-循环.md index e02557d..5ddec75 100644 --- a/doc/tutorial/08-循环.md +++ b/doc/tutorial/08-循环.md @@ -61,7 +61,7 @@ Marqdo 用 `-`(无序列表)表达循环。遍历列表用 `- [项](集合)` 黄瓜 ``` -> 遍历字典遍历的是键;要取值,用脚注取元(见[第 9 章](./09-集合.md))。 +> 遍历字典遍历的是键;要取值,用链接取元 `[键](集合)`(见[第 9 章](./09-集合.md))。 ## 8.3 while 循环:`- 条件` diff --git a/doc/tutorial/09-集合.md b/doc/tutorial/09-集合.md index 203cf34..51bc4b2 100644 --- a/doc/tutorial/09-集合.md +++ b/doc/tutorial/09-集合.md @@ -14,7 +14,7 @@ Marqdo 用 **GFM 表格**直接构造数据集合。表格的**几何形状**决 | 值 | 值 | ``` -表格绑定变量名**需要反引号**(不在 `*…*` 内)。 +表格绑定变量名**需要反引号**(不在粗体代码 `**…**` 内时)。 ## 9.2 单列竖表 → 列表(List) @@ -101,63 +101,64 @@ Marqdo 用 **GFM 表格**直接构造数据集合。表格的**几何形状**决 | ≥2 列 + 0 行 | `Map`(键存在,值空列表) | | 首列 `@`/`行`/`row` | `List` of `Map`(行向记录) | -## 9.7 脚注取元:`[^…]` +## 9.7 链接取元:`[键](集合)` -用 Markdown 脚注外形从集合取元素(**表达式级**,可链式)。 +主语法与 foreach 同形:**方括号 = 取出的名字,圆括号 = 从哪取**(见 [collection-access-link.md](../design/collection-access-link.md))。 ### 从列表按下标取 **下标是 1-based**(与人类读表一致): ```markdown -*第一 = 篮子[^1]* -> print text=`第一` # 苹果 +**第一 = [1](篮子)** +**打印 内容=`第一`** ``` ### 从字典按键取 ```markdown -*种 = 分类[^苹果]* -> print text=`种` # 水果 +**种 = [苹果](分类)** +**打印 内容=`种`** +``` + +### 动态键 + +```markdown +**名 = "拿铁"** +**价 = [`名`](菜单)** ``` ### 嵌套取元 ```markdown -*第一种苹果 = 货架[^苹果][^1]* # 先键,再下标 → 红富士 -``` - -### 基名的反引号 - -`` 名[^键] `` 与 `` `名`[^键] `` 等价(紧跟 `[^` 时可省略反引号): - -```markdown -*种 = `分类`[^苹果]* +**第一种苹果 = [1]([苹果](货架))** ``` ### 插值中的取元 -在**调用实参值 / 引号字符串**里,`` `变量` `` 后**紧跟**(无空白)`[^…]` 时也按取元解析,而不必先绑定再输出: +在**调用实参值 / 引号字符串**里也可以写链接取元(或过渡期的脚注形): ```markdown -> print text=苹果单价:`水果价格`[^苹果] # 输出:苹果单价:5 -> print text=第一种:`货架`[^苹果][^1] # 链式取元 → 红富士 -> print text="价 `水果价格`[^香蕉] 元" # 引号字符串内也可取元 → 价 3 元 +> print text=苹果单价:[苹果](`水果价格`) +> print text=第一种:[1]([苹果](`货架`)) ``` -> 规则:`` `变量` [^…] ``(**有空白**)时 `[^…]` 仍是普通文本;只有 `` `变量`[^…] ``(无空白)才算取元。 +### 过渡:脚注取元 `` 集合[^键] `` + +旧写法 `` 分类[^苹果] `` / `` `分类`[^苹果] `` **仍可解析**;新代码与教程示例请用链接形。脚注兼容金样见 `tests/structure/footnote*`。 > 规则: -> - **List**:标签须为纯数字(1-based);`[^0]` 或越界 → 报错。 -> - **Map**:标签为键文本(含纯数字键,如 `[^00]`);缺键 → 报错。 +> - **List**:键须为纯数字(1-based);`[0](…)` 或越界 → 报错。 +> - **Map**:键为键文本;缺键 → 报错。 > - 文末的 `[^1]: …` 定义块仍是注释,与取元无关。 +> - `]` 后**紧邻** `(` 才是取元;否则 `[名字]` 可能是[方括号标记调用](../design/bracket-call-modifiers.md)。 ## 9.8 表格单元格是表达式 数据单元格支持表达式(与调用实参值语法相同):裸词、数字、`` `var` ``、算术、引号串。URL / `gpt-4o-mini` 等按路径/连字符折叠为文本。 ```markdown -*k = "secret"* +**k = "secret"** `cfg` = @@ -177,7 +178,7 @@ Marqdo 用 **GFM 表格**直接构造数据集合。表格的**几何形状**决 |------|------| | 5 | 3 | -> print text=苹果单价:`水果价格`[^苹果] +**打印 内容="苹果单价:" + [苹果](水果价格)** `购物单` = @@ -187,7 +188,7 @@ Marqdo 用 **GFM 表格**直接构造数据集合。表格的**几何形状**决 | 2 | 香蕉 | 3 | - [行](购物单) - > print text=`行`[^品名] × `行`[^数量] + **打印 内容=[品名](行) + " × " + [数量](行)** ``` 输出: diff --git a/doc/tutorial/12-标准库.md b/doc/tutorial/12-标准库.md index 695a0dd..e7c53e4 100644 --- a/doc/tutorial/12-标准库.md +++ b/doc/tutorial/12-标准库.md @@ -69,7 +69,7 @@ import json:lib/json.mq.md > print text=第一行`nl`[^n]第二行 # 换行还原 ``` -> **字典操作**:本地字典的读取用脚注取元 `变量[^键]`,**不要**用 `json.get`。`json.get` / `json.set` 仅用于跨文本边界的序列化场景(例如与外部 JSON API 交换数据时)。构造字典用 GFM 横表(见[第 9 章](./09-集合.md))。 +> **字典操作**:本地字典的读取用链接取元 `[键](变量)`(过渡期也可用 `` 变量[^键] ``),**不要**用 `json.get`。`json.get` / `json.set` 仅用于跨文本边界的序列化场景(例如与外部 JSON API 交换数据时)。构造字典用 GFM 横表(见[第 9 章](./09-集合.md))。 `json` 常用函数: | 函数 | 作用 | diff --git a/doc/tutorial/14-网络与Web扩展.md b/doc/tutorial/14-网络与Web扩展.md index 3002561..7f335bc 100644 --- a/doc/tutorial/14-网络与Web扩展.md +++ b/doc/tutorial/14-网络与Web扩展.md @@ -171,7 +171,7 @@ import web:ext/web/web.mq.md ## 14.6 字典操作:用表格与取元,不用 `json.get`/`json.set` -Marqdo 用 **GFM 表格**构造字典、用 **脚注取元 `变量[^键]`** 读取字典——这是语言原生能力,是「代码即文档」的体现。**不要**用 `json.get` / `json.set` 读写本地字典(那只用于文本 ↔ 结构化的序列化,如 `json.parse` / `json.stringify`)。 +Marqdo 用 **GFM 表格**构造字典、用 **链接取元 `[键](变量)`** 读取字典——这是语言原生能力,是「代码即文档」的体现。**不要**用 `json.get` / `json.set` 读写本地字典(那只用于文本 ↔ 结构化的序列化,如 `json.parse` / `json.stringify`)。 构造字典(横表,≥2 列 + 1 行): diff --git a/doc/tutorial/README.md b/doc/tutorial/README.md index 186af90..b84314d 100644 --- a/doc/tutorial/README.md +++ b/doc/tutorial/README.md @@ -33,7 +33,7 @@ | 章节 | 内容 | 你能学会什么 | |------|------|-------------| -| [第 9 章:集合(表格)](./09-集合.md) | 列表、字典、记录、脚注取元 | 用 Markdown 表格组织数据 | +| [第 9 章:集合(表格)](./09-集合.md) | 列表、字典、记录、链接取元 | 用 Markdown 表格组织数据 | ### 第五部分 · 面向对象与模块