Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
- [Contributing To Sway](./reference/contributing_to_sway.md)
- [Keywords](./reference/keywords.md)
- [Experimental Features](./reference/experimental_features.md)
- [Appendix: Operators & Symbols](./reference/appendix_operators_symbols.md)
- [Forc Reference](./forc/index.md)
- [Manifest Reference](./forc/manifest_reference.md)
- [Workspaces](./forc/workspaces.md)
Expand Down
76 changes: 76 additions & 0 deletions docs/book/src/reference/appendix_operators_symbols.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Appendix: Operators & Symbols

This appendix is a quick reference for the operators and symbolic tokens
available in Sway. It complements the [Keywords](./keywords.md) page and the
[Basics](../basics/index.md) sections.

## Arithmetic Operators

| Operator | Meaning | Example |
| -------- | ------- | ------- |
| `+` | Addition | `a + b` |
| `-` | Subtraction | `a - b` |
| `*` | Multiplication | `a * b` |
| `/` | Division | `a / b` |
| `%` | Remainder | `a % b` |

## Comparison Operators

| Operator | Meaning | Example |
| -------- | ------- | ------- |
| `==` | Equal to | `a == b` |
| `!=` | Not equal to | `a != b` |
| `>` | Greater than | `a > b` |
| `<` | Less than | `a < b` |
| `>=` | Greater than or equal | `a >= b` |
| `<=` | Less than or equal | `a <= b` |

## Logical Operators

| Operator | Meaning | Example |
| -------- | ------- | ------- |
| `&&` | Logical AND | `a && b` |
| `||` | Logical OR | `a || b` |
| `!` | Logical NOT | `!a` |

## Bitwise Operators

| Operator | Meaning | Example |
| -------- | ------- | ------- |
| `&` | Bitwise AND | `a & b` |
| `|` | Bitwise OR | `a | b` |
| `^` | Bitwise XOR | `a ^ b` |
| `<<` | Left shift | `a << b` |
| `>>` | Right shift | `a >> b` |

## Assignment Operators

| Operator | Meaning | Example |
| -------- | ------- | ------- |
| `=` | Assign | `let a = b;` |
| `+=` | Add and assign | `a += b` |
| `-=` | Subtract and assign | `a -= b` |
| `*=` | Multiply and assign | `a *= b` |
| `/=` | Divide and assign | `a /= b` |
| `%=` | Remainder and assign | `a %= b` |

## Symbolic Tokens

| Symbol | Meaning |
| ------ | ------- |
| `::` | Path separator, e.g. `std::vec::Vec` |
| `->` | Return type, e.g. `fn f() -> u64` |
| `=>` | Match arm, e.g. `0 => "zero"` |
| `@` | Read storage value, e.g. `@storage_field` |
| `..` | Range, e.g. `0..10` |
| `..=` | Inclusive range, e.g. `0..=10` |
| `_` | Wildcard / unused binding |
| `?` | Propagate error from `Result` |

## Compound Type Constructors

| Symbol | Meaning | Example |
| ------ | ------- | ------- |
| `[]` | Array / vector literal | `let v = [1, 2, 3];` |
| `()` | Tuple literal | `let t = (1, true);` |
| `{}` | Block / struct literal | `{ let x = 1; x }` |
1 change: 1 addition & 0 deletions docs/book/src/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
- [Contributing to Sway](./contributing_to_sway.md)
- [Keywords](./keywords.md)
- [Experimental Features](./experimental_features.md)
- [Appendix: Operators & Symbols](./appendix_operators_symbols.md)