summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/reference/syntax.md1
-rw-r--r--docs/reference/types.md30
2 files changed, 21 insertions, 10 deletions
diff --git a/docs/reference/syntax.md b/docs/reference/syntax.md
index d0cd80d7..3209e8e5 100644
--- a/docs/reference/syntax.md
+++ b/docs/reference/syntax.md
@@ -85,6 +85,7 @@ a table listing all syntax that is available in code mode:
| Field access | `{x.y}` | [Scripting]($scripting/#fields) |
| Method call | `{x.flatten()}` | [Scripting]($scripting/#methods) |
| Function call | `{min(x, y)}` | [Function]($type/function) |
+| Argument spreading | `{min(..nums)}` | [Arguments]($type/arguments) |
| Unnamed function | `{(x, y) => x + y}` | [Function]($type/function) |
| Let binding | `{let x = 1}` | [Scripting]($scripting/#bindings) |
| Named function | `{let f(x) = 2 * x}` | [Function]($type/function) |
diff --git a/docs/reference/types.md b/docs/reference/types.md
index 3e08d670..fe01d4c1 100644
--- a/docs/reference/types.md
+++ b/docs/reference/types.md
@@ -1066,26 +1066,36 @@ whose fields have the values of the given arguments.
# Arguments
Captured arguments to a function.
+## Argument Sinks
Like built-in functions, custom functions can also take a variable number of
arguments. You can specify an _argument sink_ which collects all excess
arguments as `..sink`. The resulting `sink` value is of the `arguments` type. It
-exposes methods to access the positional and named arguments and is iterable
-with a [for loop]($scripting/#loops). Inversely, you can spread
-arguments, arrays and dictionaries into a function call with the spread operator:
-`{func(..args)}`.
+exposes methods to access the positional and named arguments.
-## Example
```example
-#let format(title, ..authors) = [
- *#title* \
- _Written by #(authors
+#let format(title, ..authors) = {
+ let by = authors
.pos()
- .join(", ", last: " and "));._
-]
+ .join(", ", last: " and ")
+
+ [*#title* \ _Written by #by;_]
+}
#format("ArtosFlow", "Jane", "Joe")
```
+## Spreading
+Inversely to an argument sink, you can _spread_ arguments, arrays and
+dictionaries into a function call with the `..spread` operator:
+
+```example
+#let array = (2, 3, 5)
+#calc.min(..array)
+
+#let dict = (fill: blue)
+#text(..dict)[Hello]
+```
+
## Methods
### pos()
Returns the captured positional arguments as an array.