Files
marqdo/skills/marqdo/examples.md
T
cflmyandCursor ff252fd469 feat(web): land Artifact serve/endpoint path and retire compose golds
Wire data_source into Document render, register Endpoint handlers via
run_artifact, restore marqdo-blog as an Artifact site, and replace old
compose_* web golds with ADR 0007 fixtures and docs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 11:36:45 +08:00

5.2 KiB

Marqdo examples (AI)

1. Hello (English)

# main

> print text=Hello World!

2. Hello (Chinese builtins)

# main

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

3. Function + named call + body end

# main

Greeting via a nested function:

> greet who=Marqdo

## greet
    + `who`

> print text=Hello, `who`!

---

4. Bindings and return

# main

*a = 2*
*b = > add_one n=`a`*
> print text=`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=`果`

6b. Map table + footnote get

# main

`分类` =

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

*种 = 分类[^苹果]*
> print text=`种`

*第一 = 篮子[^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.

Row-oriented records (SQL-like): first header @ / 行 / row → list of maps (marker column excluded):

`订单` =

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

*名 = 订单[^1][^品名]*

6c. 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.

7. Import text stdlib

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

# main

*parts = > split value=a,b,c sep=,*
> print text=`parts`

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*
> print text=`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 / 自.

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 = > json.set map=`self` key=extra value=1*
**self**

11. Agent layout (ABI)

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

# main

> load_native

*ws = > agent*
*n = > `ws`.ensure_layout*
> print text=`n`

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

12. What not to emit

# BAD — bold is return, not print
**Hello**

# BAD — Python control keywords
if x > 0:
  print(x)

# BAD — wrapping a call in italics
*> 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

13. Dynamic site (Web Artifact, minimal)

index.mq.md:

---
type: web
title: Hello
route: /
method: GET
---

# Hello

Executable document as a page.

serve.mq.md:

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

# main

> web.serve root="." host="127.0.0.1" port=8080
  • Import ext/web/web.mq.md or ext/web/网页.mq.md — not both.
  • Full Artifact blog: examples/marqdo-blog/ (pages/ · api/ · db/ · data_source).
  • Design: doc/design/ext-web-artifact.md · ADR 0007. No compose_* / configure.

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"*
> print text=`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.