# Appendix A: Keywords and operators

> Appendix A: every Alice keyword, modifier and operator, with a one-line meaning and the chapter that explains it.

Canonical: https://alice-lang.org/documentation/learn/keywords/

[Documentation index](https://alice-lang.org/documentation/llms.txt) · [Complete book](https://alice-lang.org/llms-full.txt)

This appendix lists the words and symbols with a fixed meaning in Alice. The [syntax reference](https://alice-lang.org/documentation/reference/syntax.md) has the full grammar.

## Keywords

| Keyword                                                    | Meaning                                                       | Chapter                                                                                                                            |
| ---------------------------------------------------------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `def` ... `end`                                            | define a method; `def name = expr` is the one-line form       | [3](https://alice-lang.org/documentation/learn/common-concepts.md)                                                                 |
| `return`, `yield`                                          | leave a method with a value; call the method's block          | [3](https://alice-lang.org/documentation/learn/common-concepts.md), [4](https://alice-lang.org/documentation/learn/collections.md) |
| `if`, `elsif`, `else`, `unless`                            | choose a branch; `unless` is "if not"; postfix forms `x if c` | [3](https://alice-lang.org/documentation/learn/common-concepts.md)                                                                 |
| `case`, `when`, `in`, `then`                               | compare with `when`, match patterns with `in`                 | [3](https://alice-lang.org/documentation/learn/common-concepts.md), [7](https://alice-lang.org/documentation/learn/sum-types.md)   |
| `while`, `until`, `for` ... `in`, `loop`, `do`             | loops; `do ... end` is a block                                | [3](https://alice-lang.org/documentation/learn/common-concepts.md)                                                                 |
| `break`, `next`                                            | leave a loop; skip to its next round                          | [2](https://alice-lang.org/documentation/learn/guessing-game.md)                                                                   |
| `begin`, `rescue`, `else`, `ensure`, `raise`, `retry`      | exceptions                                                    | [8](https://alice-lang.org/documentation/learn/errors.md)                                                                          |
| `val`                                                      | a binding that cannot be reassigned                           | [3](https://alice-lang.org/documentation/learn/common-concepts.md)                                                                 |
| `nil`, `true`, `false`, `self`, `super`                    | literal values, the current object, the parent's method       | [3](https://alice-lang.org/documentation/learn/common-concepts.md), [6](https://alice-lang.org/documentation/learn/types.md)       |
| `class`, `struct`, `record`, `enum`, `module`, `interface` | define types and modules                                      | [6](https://alice-lang.org/documentation/learn/types.md), [7](https://alice-lang.org/documentation/learn/sum-types.md)             |
| `abstract`, `private`, `protected`, `public`               | abstract members; visibility                                  | [6](https://alice-lang.org/documentation/learn/types.md)                                                                           |
| `getter`, `setter`, `property`                             | field accessors                                               | [6](https://alice-lang.org/documentation/learn/types.md)                                                                           |
| `include`, `extend`, `using`, `require`, `namespace`       | mixins; imports; loading files; .NET namespaces               | [6](https://alice-lang.org/documentation/learn/types.md), [14](https://alice-lang.org/documentation/learn/dotnet.md)               |
| `own`, `borrow`, `scope`                                   | ownership contracts and lifetime regions                      | [9](https://alice-lang.org/documentation/learn/ownership.md)                                                                       |
| `pure`, `safe`, `inline`                                   | method modifiers: no effects; no ambient authority; inline    | [10](https://alice-lang.org/documentation/learn/safety.md), [12](https://alice-lang.org/documentation/learn/performance.md)        |
| `par`, `par for`                                           | fork two pure calls; require a parallel loop                  | [11](https://alice-lang.org/documentation/learn/parallelism.md)                                                                    |
| `spawn`, `async`, `await`, `for await`                     | threads and asynchronous code                                 | [15](https://alice-lang.org/documentation/learn/async.md)                                                                          |
| `gpu for`, `gpu` ... `end`                                 | GPU loops and device regions                                  | [16](https://alice-lang.org/documentation/learn/gpu.md)                                                                            |
| `lib`, `fun`, `unsafe`                                     | C libraries and raw pointers                                  | [17](https://alice-lang.org/documentation/learn/native.md)                                                                         |
| `unchecked` ... `end`                                      | integer arithmetic that wraps                                 | [3](https://alice-lang.org/documentation/learn/common-concepts.md)                                                                 |
| `rule`                                                     | a provable property                                           | [13](https://alice-lang.org/documentation/learn/proofs.md)                                                                         |
| `it`, `_1` ... `_9`                                        | implicit block parameters                                     | [4](https://alice-lang.org/documentation/learn/collections.md)                                                                     |

## Operators

| Operator                  | Meaning                                                          |
| ------------------------- | ---------------------------------------------------------------- |
| `+ - * / % **`            | arithmetic; integer `/` and `%` round down; overflow raises      |
| `&+ &- &*`                | wrapping integer arithmetic                                      |
| `== != < <= > >=`         | comparison                                                       |
| `<=>`                     | three-way comparison: -1, 0 or 1                                 |
| `&& \|\| !`, `and or not` | logic; `x \|\| default` also supplies a value for `nil`          |
| `= += -= *= /=`           | assignment and compound assignment                               |
| `c ? a : b`               | conditional expression                                           |
| `..`, `...`               | inclusive and exclusive ranges                                   |
| `<<`                      | append to a `List`, a `StringBuilder` or a `String.build` buffer |
| `=~`, `!~`                | regular-expression match position, and its negation              |
| `%` on a string           | format: `"%05d" % [42]`                                          |
| `&:name`                  | a block that calls `name` on its argument                        |
| `->(x : T) { ... }`       | a lambda                                                         |
| `::`                      | a constant or variant inside a type or module: `Light::Red`      |
| `@field`, `@@class_field` | instance and class fields                                        |
| `x?` in a type            | nilable: `String?`                                               |
| `@[Attribute]`            | an attribute, Alice or .NET                                      |

Classes can define most operators as methods: `def +(other : T)`, `def <=>(other : T)`, `def [](i : Int32)`. See [chapter 6](https://alice-lang.org/documentation/learn/types.md).

## Attributes used in this book

| Attribute                    | Effect                                                      |
| ---------------------------- | ----------------------------------------------------------- |
| `@[Stack]`                   | a struct that may only live on the stack                    |
| `@[SoA]`                     | a record struct stored as columns in `SoA(T)`               |
| `@[Hot]`                     | optimize fully from the first call                          |
| `@[Native]`                  | compile the method to C with clang                          |
| `@[Link("lib")]`, `@[Fast]`  | the shared library of a `lib`; a call without GC transition |
| `@[JSExport]`, `@[JSImport]` | WebAssembly interop with JavaScript                         |
| `@[Test]`, `@[Cases(...)]`   | xUnit-style tests                                           |

## Continue reading

- Previous: [22. Alice for AI agents](https://alice-lang.org/documentation/learn/agents.md)
- Next: [Appendix B: Error codes](https://alice-lang.org/documentation/learn/error-codes.md)
