Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
370 changes: 370 additions & 0 deletions docs/design/vectorization.md

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions manual/src/reference/types/tuple.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,29 @@ assert_eq(b, (1,2,3,4,5));
## Operators

{{#include ../../snippets/list-operators.md}}

## Vectorization

Operators broadcast element-wise over tuples. Both arguments must be tuples
of the same length, or one side may be a scalar that broadcasts:

```ndc
assert_eq((1, 2) + (3, 4), (4, 6));
assert_eq(-(1, 2, 3), (-1, -2, -3));
assert_eq((1, 2) + 5, (6, 7));
assert_eq(("a", "b") ++ ("c", "d"), ("ac", "bd"));
```

Vectorization only kicks in for operator syntax (`a + b`, `-x`,
`a ++ b`, etc.). Regular function calls never broadcast, so
`f((1, 2, 3))` passes the whole tuple to `f` and does not call `f`
once per element.

Mixed-element tuples or length mismatches error rather than silently
producing wrong results:

```ndc
(1, 2, 3) + (4, 5) // ERROR: no overload matches
(1, "a") + (2, "b") // ERROR: no overload accepts both pairs
```

273 changes: 235 additions & 38 deletions ndc_analyser/src/analyser.rs

Large diffs are not rendered by default.

Loading
Loading