-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
166 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,68 @@ | ||
# Types, part II | ||
|
||
In Typst, most of things are **immutable**. You can't change content, you can just create new using this one (for example, using addition). | ||
|
||
Immutability is very important for Typst since it tries to be _as pure language as possible_. Functions do nothing outside of returning some value. | ||
|
||
However, purity is partly "broken" by these types. They are *super-useful* and not adding them would make Typst much pain. | ||
|
||
However, using them adds complexity. | ||
|
||
## Arrays (`array`) | ||
|
||
## Dictionaries (`dict`) | ||
> [Link to Reference](https://typst.app/docs/reference/foundations/array/). | ||
Mutable object that stores data with their indices. | ||
|
||
### Working with indices | ||
``` | ||
#let values = (1, 7, 4, -3, 2) | ||
// take value at index 0 | ||
#values.at(0) \ | ||
// set value at 0 to 3 | ||
#(values.at(0) = 3) | ||
// negative index => start from the back | ||
#values.at(-1) \ | ||
// add index of something that is even | ||
#values.find(calc.even) | ||
``` | ||
|
||
### Iterating methods | ||
``` | ||
#let values = (1, 7, 4, -3, 2) | ||
// leave only what is odd | ||
#values.filter(calc.odd) \ | ||
// create new list of absolute values of list values | ||
#values.map(calc.abs) \ | ||
// reverse | ||
#values.rev() \ | ||
// convert array of arrays to flat array | ||
#(1, (2, 3)).flatten() \ | ||
// join array of string to string | ||
#(("A", "B", "C") | ||
.join(", ", last: " and ")) | ||
``` | ||
|
||
## Dictionaries (`dict`) | ||
|
||
> [Link to Reference](https://typst.app/docs/reference/foundations/dictionary/). | ||
Dictionaries are objects that store a string "key" and a value, associated with that key. | ||
|
||
``` | ||
#let dict = ( | ||
name: "Typst", | ||
born: 2019, | ||
) | ||
#dict.name \ | ||
#(dict.launch = 20) | ||
#dict.len() \ | ||
#dict.keys() \ | ||
#dict.values() \ | ||
#dict.at("born") \ | ||
#dict.insert("city", "Berlin ") | ||
#("name" in dict) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Labels | ||
|
||
## Get chapter of label | ||
|
||
``` | ||
#let ref-heading(label) = locate(loc => { | ||
let elems = query(label, loc) | ||
if elems.len() != 1 { | ||
panic("found multiple elements") | ||
} | ||
let element = elems.first() | ||
if element.func() != heading { | ||
panic("label must target heading") | ||
} | ||
link(label, element.body) | ||
}) | ||
= Design <design> | ||
#lorem(20) | ||
= Implementation | ||
In #ref-heading(<design>), we discussed... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Operations | ||
|
||
## Fractions | ||
|
||
``` | ||
$ | ||
p/q, p slash q, p\/q | ||
$ | ||
``` | ||
|
||
### Slightly moved: | ||
``` | ||
#let mfrac(a, b) = move(a, dy: -0.2em) + "/" + move(b, dy: 0.2em, dx: -0.1em) | ||
$A\/B, #mfrac($A$, $B$)$ | ||
``` |