Skip to content

Commit cee4597

Browse files
feat: 重新安排复合类型 (#34)
1 parent c689a03 commit cee4597

File tree

6 files changed

+314
-302
lines changed

6 files changed

+314
-302
lines changed

src/basic/scripting-access.typ

Lines changed: 0 additions & 153 deletions
This file was deleted.

src/basic/scripting-block-and-expression.typ

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Typst中绝大部分语法结构都可作表达式,可以说学习完了所有
99
+ 如果一个语句能产生值,那么该语句的结果是按*控制流*顺序所产生所有值的折叠。
1010
+ 否则,如果一个语句不能产生值,那么该语句的结果是```typc none```
1111
+ 特别地,任意类型 $T$ 的值 $v$```typc none```折叠仍然是值本身。
12-
$ forall v in T union {"none"}, op("fold")_T (v, "none") = v $
1312
]
1413

1514
#pro-tip[
@@ -181,31 +180,11 @@ Typst支持对数字的算数运算,其中浮点运算遵守IEEE-754标准。
181180
table(
182181
columns: (33pt * 0.6,) * 2 + (33pt,) * 3,
183182
stroke: 0.5pt,
184-
$p$,
185-
$q$,
186-
$not p$,
187-
$p or q$,
188-
$p and q$,
189-
$0$,
190-
$0$,
191-
$1$,
192-
$0$,
193-
$0$,
194-
$0$,
195-
$1$,
196-
$1$,
197-
$1$,
198-
$0$,
199-
$1$,
200-
$0$,
201-
$0$,
202-
$1$,
203-
$0$,
204-
$1$,
205-
$1$,
206-
$0$,
207-
$1$,
208-
$1$,
183+
$p$, $q$, $not p$, $p or q$, $p and q$,
184+
$0$, $0$, $1$, $0$, $0$,
185+
$0$, $1$, $1$, $1$, $0$,
186+
$1$, $0$, $0$, $1$, $0$,
187+
$1$, $1$, $0$, $1$, $1$,
209188
)
210189
}
211190

@@ -229,48 +208,6 @@ Typst支持对数字的算数运算,其中浮点运算遵守IEEE-754标准。
229208
#repr(a += 2), #a, #repr(a -= 2), #a, #repr(a *= 2), #a, #repr(a /= 2), #a
230209
```)
231210

232-
== 数组和字典的「解构赋值」
233-
234-
除了使用字面量「构造」元素,Typst还支持「构造」的反向操作:「解构赋值」。顾名思义,你可以在左侧用相似的语法从数组<grammar-destruct-array>或字典中获取值并赋值到*对应*的变量上。<grammar-destruct-dict>
235-
236-
#code(```typ
237-
#let (attr: a) = (attr: [kawaii\~])
238-
#a
239-
```)
240-
241-
「解构赋值」必须一一对应,但你也可以使用「占位符」(`_`)或「延展符」(`..`)以作*部分*解构:<grammar-destruct-array-eliminate>
242-
243-
#code(```typ
244-
#let (first, ..) = (1, 2, 3)
245-
#let (.., second-last, _) = (7, 8, 9, 10)
246-
#first, #second-last
247-
```)
248-
249-
数组的「解构赋值」有一个妙用,那就是重映射内容。<grammar-array-remapping>
250-
251-
#code(```typ
252-
#let (a, b, c) = (1, 2, 3)
253-
#let (b, c, a) = (a, b, c); #a, #b, #c
254-
```)
255-
256-
特别地,如果两个变量相互重映射,这种操作被称为「交换」:<grammar-array-swap>
257-
258-
#code(```typ
259-
#let (a, b) = (1, 2)
260-
#((a, b) = (b, a)); #a, #b
261-
```)
262-
263-
// field access
264-
// - dictionary
265-
// - symbol
266-
// - module
267-
// - content
268-
269-
=== 参数解构 <grammar-destructing-param>
270-
271-
#todo-box[写完]
272-
todo参数解构。
273-
274211
== 代码块 <grammar-code-block>
275212

276213
除了字面量,由于「面向表达式编程」,「代码块」也可以作为表达式的「项」。在Typst中,代码块和内容块是等同的。将「内容块」与「代码块」作比较:

0 commit comments

Comments
 (0)