Files
marqdo/doc/tutorial/01-入门.md
cflmyandCursor 34915e3b16 docs: align remaining tutorial chapters with markup v0.3
Teach bold-as-code, italic-as-return, link-index, and bracket-marked calls across chapters 1–8/10–14 and Skill reference so teaching matches the runtime.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-14 13:18:28 +08:00

89 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 第 1 章:Marqdo 是什么
## 1.1 一句话介绍
**Marqdo = Markdown(Marq)+ 执行(do)**。它把 Markdown 的**标记当作编程语法**:同一个 `.mq.md` 文件,打开给人看是文档,运行给机器看是程序。
在大型项目里,说明、示例与实现往往分叉成三份「真相」,改一处忘另一处。Marqdo 让这三者**同源**——你写的文档本身就是可执行的代码。
## 1.2 与其他语言的区别
传统编程语言(如 Python)需要单独写文档和注释;Marqdo 反过来了——**文档本身就是程序**。
| 传统语言 | Marqdo |
|----------|--------|
| 代码在 `.py`,文档在 `.md` | 代码与文档同在 `.mq.md` |
| `def` / `if` / `for` / `return` 是关键字 | 用 Markdown 标记 `##` / `1.` / `-` / `**代码**` / `*返回*` 表达 |
| 注释用 `#` 或 `//` | **无标记的叙述就是注释** |
| 大括号 `{}` 或缩进界定代码块 | 标题层级 `#` / `##` 界定作用域 |
关键点:**不要**试图写 `if`、`else`、`while`、`for`、`def`、`return` 这些关键字——它们不是 Marqdo 的语法。控制流由 Markdown 承担。
## 1.3 安装
Marqdo 用 Rust 编写。从以下任一方式获取:
- **发布包**:从 GitHub Releases 下载预编译二进制(已内置标准库)。
- **源码构建**:
```bash
git clone https://github.com/cflmy/marqdo.git
cd marqdo
cargo build --release
# 二进制位于 target/release/marqdo
```
验证安装:
```bash
marqdo --version
```
## 1.4 第一个程序
创建一个文件 `hello.mq.md`:
```markdown
# Hello World
这是叙述文字,也就是注释。
> print text=Hello World!
```
- `# Hello World` —— 对象标题。`# main` 是入口;当文件只有唯一一个顶层 `#` 对象时,它也可作为入口。
- 空行后的普通文字是**注释**(叙述)。
- `> print text=Hello World!` —— 调用内置函数 `print` 输出一行文本。
运行:
```bash
marqdo run hello.mq.md
```
输出:
```text
Hello World!
```
## 1.5 中英双语内核
Marqdo 内核内置函数都有中英别名,**无需导入,可混用**:
```markdown
# main
> 打印 内容=你好,世界!
```
`打印` 与 `print` 是同一个内置函数,`内容` 与 `text` 是同一个参数名。
## 1.6 文件后缀:`.mq.md`
Marqdo 程序的**后缀必须是 `.mq.md`**(可执行源文件),不能用普通的 `.md`。一个 `.md` 文件默认只是文档;一个 `.mq.md` 文件既是文档又是程序。
## 1.7 下一步
你已经能写出并运行第一个程序了。接下来学习[第 2 章:基本语法](./02-基本语法.md)——理解 `.mq.md` 里哪些是代码、哪些是注释,以及标识符的写法。