Files
marqdo/examples/syntax-tour/index.mq.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

190 lines
3.5 KiB
Markdown
Raw 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.
---
markup: occlusion
import:
table: lib/table.mq.md
title: Marqdo 语法全景(v1.6 现状)
description: 一页看完全部现行语法:遮蔽、调用、取值、循环、分支、表格、契约
---
# main
—— 1. 变量与插值 ——
**π = 3.14159**
**名 = "Marqdo"**
**开 = True**
> print text=名字是`名`,π 约等于 `π`
反引号取值,正文里的反引号是插值:
`长度` = [名字长度](len(`名`))
> print text=`名` 的长度是 `长度`
—— 2. 函数:参数、返回、契约 ——
税率函数接收档位与金额,返回应缴税额。
> 计税 档位=2 金额=100
`税率表` =
| 档位 | 税率 |
|------|------|
| 1 | 0.03 |
| 2 | 0.1 |
| 3 | 0.2 |
—— 3. 调用的四种形态 ——
> print text="形态一:> 前缀 + 具名实参"
**甲 = 加(1 2)**
**乙 = 加(1, 2)**
**丙 = 加(加(1 2), 10)**
**丁 = 加一 号(31)**
> print text=形态二 括号位置实参:`甲`
> print text=形态三 括号逗号:`乙`
> print text=形态四 嵌套:`丙`
> print text=形态五 带空格的函数名:`丁`
—— 4. 取值:access / at / get ——
`篮子` =
| 果 |
|----|
| 苹果 |
| 梨 |
`饮品价` =
| 拿铁 | 美式 |
|------|------|
| 28 | 18 |
`取第一` = [第一颗](access(`篮子`, "1"))
`取配置` = [拿铁多少钱](access(`饮品价`, "拿铁"))
`个数` = [篮子有几颗](table.len(`篮子`))
`表取` = [用 table.get 读同一个键](table.get(`饮品价`, "美式"))
> print text=access 取列表第 1 项:`取第一`
> print text=access 取 Map 的键:`取配置`
> print text=table.len 数个数:`个数`
> print text=table.get 读键:`表取`
—— 5. 遮蔽:把实现藏进括号 ——
描述给人读,`()` 里才是机器执行的部分。
写法用 `` `名` = [描述](实现) ``(裸赋值),而不是 `**名 = [描述](实现)**`:
粗体会把描述也包成"代码味",读者一眼看到的是强调而不是人话。
`留存` = [客户留存率,模拟数据](0.42)
> print text=遮蔽的值:`留存`
未接通的功能用空载荷申报(会得到一条 warning,提醒写清返回值):
`待接` = [搜索接入,接口未接,待开发]()
> print text=空载荷桩的值:`待接`
—— 6. 循环 ——
- [篮子里的每个果子](遍历 `篮子` 为 `果`)
> print text=果子:`果`
`n` = 3
- `n` > 0
> print text=倒数 `n`
**n = n - 1**
—— 7. 分支 ——
**分数 = 86**
1. `分数` >= 90
> print text=等级 A
2. `分数` >= 60
> print text=等级 B
3. *
> print text=等级 C
—— 8. 表格的三态 ——
竖表(单列)→ List:
`城市` =
| 城 |
|----|
| 北京 |
| 上海 |
横表(1 行)→ Map:
`配置` =
| 超时 | 重试 |
|------|------|
| 30 | 2 |
行向(首列 `行`)→ List of Map:
`订单` =
| 行 | 品名 | 数量 |
|----|------|------|
| 1 | 苹果 | 2 |
| 2 | 梨 | 3 |
- [每条订单](遍历 `订单` 为 `单`)
> print text=订单:`单`
> print text=配置超时是 `配置`
—— 9. 值类型 ——
**整数 = 42**
**小数 = 1.5**
**真值 = True**
**空值 = None**
**串 = "引号里的文本"**
> print text=整数 `整数` 小数 `小数` 真值 `真值` 空值 `空值`
> print text=`串`
—— 10. 收尾 ——
> print text="以上全部可执行;描述只是描述,机器只跑括号里的东西。"
## 计税
+ `档位`
+ `金额`
**率 = 0.1**
1. `档位` == 1
**率 = 0.03**
2. `档位` == 3
**率 = 0.2**
3. *
**率 = 0.1**
*`金额` * `率`*
## 加
+ `a`
+ `b`
*`a` + `b`*
## 加一 号
+ `n`
*`n` + 1*