Files
marqdo/.cursor/skills/marqdo/examples.md
T
cflmyandCursor 687c168014 feat(parse): use nested YAML import: maps instead of one-liner binds
Frontmatter imports are now valid YAML (`import:` / `导入:` with bind→target
entries), removing spaced keys. Add `marqdo migrate imports`, hard-error the
old one-liner form, and migrate lib/ext/examples/tests/docs accordingly.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-23 19:33:58 +08:00

8.2 KiB
Raw Blame History

Marqdo examples (AI)

v0.3: **…** = code (assign / call); *…* = return. Prefer [key](coll) over footnote get. Bracket calls: 礼貌 [问候] x.

1. Hello (English)

# main

> print text=Hello World!

2. Hello (Chinese builtins)

# main

> 打印 内容=你好,世界!

3. Function + named call + empty return

# main

Greeting via a nested function:

> greet who=Marqdo

## greet
    + `who`

> 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

# main

**a = 2**
**b = add_one n=`a`**
**打印 内容=`b`**

## add_one
    + `n`

*n + 1*

5. Branch with else

# main

**n = 0**

1. `n` > 0
  > print text=positive
2. `n` < 0
  > print text=negative
3. *
  > print text=zero

6. Foreach loop

# main

`篮子` =

| 果 |
|----|
| 苹果 |

- [果](篮子)
  > print text=`果`
# main

`分类` =

| 苹果 | 黄瓜 |
|------|------|
| 水果 | 蔬菜 |

**种 = [苹果](分类)**
**打印 内容=`种`**

`篮子` =

| 果 |
|----|
| 苹果 |

**第一 = [1](篮子)**
**打印 内容=`第一`**

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):

`订单` =

| 行 | 品名 | 数量 |
|----|------|------|
| 1 | 苹果 | 2 |

**名 = [品名]([1](订单))**

6c. Bracket-marked call + modifiers

# main

**打印 内容=(礼貌 [问候] "Marqdo")**

## 问候
    + `谁`
    + `礼貌`=False

**出 = `礼貌` + ", " + `谁` + "!"**
*出*

礼貌 [问候] … → 礼貌=True. ] immediately followed by ( is index, not a call.

6d. Browser effects — tables + lib/browser (not json.set)

---
import:
  browser: lib/browser.mq.md
---

# main

`wire` =

| @ | 选择器 | 事件 | 调用 |
|---|--------|------|------|
| 1 | "#bump" | click | bump |

**`wire`**

## bump
**count = count + 1**
**label = str count**
**> browser.set_text sel="#count" text=label**

Do not build effect maps with json.set chains. See marqdo-dev.

6e. Agent / LLM result maps — GFM first (positive)

Return and soft-error packs are tables, not json.set pipelines. Full style contract: marqdo-dev §2.

---
import:
  table: lib/table.mq.md
---

## step_ok
    + `task`
    + `reply`

`out` =

| status | task | result |
|--------|------|--------|
| ok | `task` | `reply` |

*out*

## step_err
    + `task`
    + `err`

`out` =

| status | task | error |
|--------|------|-------|
| error | `task` | `err` |

*out*

## soft_http_pack
    + `msg`
    + `usage0`

**empty_tc = > table.empty_list**

`pack` =

| finish | text | error | usage | tool_calls |
|--------|------|-------|-------|------------|
| error | "" | `msg` | `usage0` | `empty_tc` |

*pack*

Do not mirror legacy ext/ai/agent.mq.md json.parse+json.set chains when adding new arms — convert the shape to a table.

7. Import text stdlib

---
title: split demo
import:
  text: lib/text.mq.md
---

# main

**parts = [text.str_split] s="a,b,c" sep=","**
**打印 内容=`parts`**

7b. Mid M1 — regex + encoding (no plugin)

---
import:
  re: lib/re.mq.md
  enc: lib/encoding.mq.md
---

# main

**`ok` = [re.is_match] text="a@b.c" pattern="@"**
**`b64` = [enc.base64_encode] text="hi"**
**打印 内容=`ok`**
**打印 内容=`b64`**

7c. Mid M6 — log + uuid

---
import:
  log: lib/log.mq.md
  uuid: lib/uuid.mq.md
---

# main

> log.info text="start"
> log.set_level level="debug"
> log.debug text="detail"
**id = [uuid.v4]**
**打印 内容=`id`**

8. Comment paragraphs (blank-line rule)

# main

This whole paragraph is a comment, including lines that look like code:
**not_executed = 1**
> print text=also still comment

After a blank line, code runs:

> print text=this runs

9. Frontmatter import only

---
description: loads math
import:
  math: lib/math.mq.md
---

# main

**t = > num value=3.5**
**打印 内容=`t`**

10. Object handle + method

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

# Greeter

## hello
    + `who`

**msg = "Hello, `who`!"**
*msg*

# Loud = > Greeter

## hello
    + `who`

**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:

# Child = > Parent
    + `name`

**self = > Parent name=`name`**
**self = [table.put] in=`self` at="extra" value=1**
*self*

11. Agent layout (ABI)

---
import:
  agent: ext/agent.mq.md
---

# main

> load_native

**ws = > agent**
**n = > `ws`.ensure_layout**
**打印 内容=`n`**

Requires MARQDO_AGENT_PLUGIN pointing at the built agent shared library (see doc/design/ext-agent.md).

12. What not to emit

# 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 as if it were a statement
*> print text=hi*

# BAD — old branch syntax (removed)
+ `x` > 0

# GOOD — ordered list arms
1. `x` > 0
  > print text=pos
2. *
  > print text=other

# GOOD — another independent branch (restart at 1.)
1. `y` > 0
  > print text=y-pos
2. *
  > print text=y-other

# GOOD — print / return
**打印 内容="hi"**
*n + 1*

13. Dynamic site (ext/web, minimal)

---
title: hello-site
import:
  web: ext/web/web.mq.md
  db: db/index.mq.md
---

# main

`shell` =

| 组件 | 样式 |
|------|------|
| nav | |

`main` =

| 属性 | 值 | 样式 |
|------|-----|------|
| 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"**
> listen app=`app`
  • Import ext/web/web.mq.md or ext/web/网页.mq.md — not both; match API language to the file.
  • Full blog/CMS patterns: examples/marqdo-blog/ (routes, SEO, RSS, auth, upload, WS).
  • Run after marqdo ext add web and building marqdo_plugin_web.

14. Quantum entanglement lab (ext/quantum Q7/Q8)

---
import:
  quantum: ext/quantum/quantum.mq.md
---

# main

`steps` =

| step | gate | qubits |
|------|------|--------|
| 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"**
**打印 内容=`red`**
  • Full lab: examples/quantum-entanglement/. Bell-only: examples/quantum-bell/.
  • theme="dark"|"light"|"bw" (default dark) on circuit / probs / bloch. Quote kind= / theme=.
  • After rebuilding the plugin: marqdo ext add quantum so view loads the new native lib.

15. Linear algebra (ext/linalg)

---
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`**

Prefer:

**`env` = > la.declare table=`shapes`**
**`P` = [A](env) * [B](env)**
**`t` = > `P`.T_ascii**
  • Infix + / - / *;ascii / T_ascii 默认化简(raw=True 可关)。
  • Formula-doc design: ext-linalg-formula-doc.md.
  • Examples: examples/linalg-transpose/, examples/linalg-svd/, examples/linalg-least-squares/.