# Special forms

Forms the evaluator treats specially, before function application. Their
names are reserved in binding positions: binding `if`, `quote`, `dotimes`
or any other name below is `E-EVAL-005`. Everything else, including every
[prelude](https://sexpgpu.041.io/docs/prelude.md) macro and [builtin](https://sexpgpu.041.io/docs/builtins.md), can be shadowed.
A malformed special form is `E-EVAL-005` with the expected shape.

## Core

| form | shape | page |
|---|---|---|
| `quote` | `(quote x)`, `'x` | |
| `quasiquote` | `` `(a ,b ,@c) `` | [macros](https://sexpgpu.041.io/docs/macros.md) |
| `if` | `(if test then [else])`; the chosen branch keeps multiple values | [control](https://sexpgpu.041.io/docs/control.md) |
| `progn` | `(progn form...)` | |
| `let` | `(let ((name value)...) body...)`, initializers in the enclosing scope | [functions](https://sexpgpu.041.io/docs/functions.md) |
| `let*` | `(let* ((name value)...) body...)`, each binding in a new scope | [functions](https://sexpgpu.041.io/docs/functions.md) |
| `setq` | `(setq name value [name value]...)`, rebinds existing variables | [functions](https://sexpgpu.041.io/docs/functions.md) |
| `lambda` | `(lambda lambda-list body...)` | [functions](https://sexpgpu.041.io/docs/functions.md) |
| `flet` | `(flet ((name lambda-list body...)...) body...)` | [functions](https://sexpgpu.041.io/docs/functions.md) |
| `labels` | the same, mutually recursive | [functions](https://sexpgpu.041.io/docs/functions.md) |
| `macrolet` | `(macrolet ((name lambda-list body...)...) body...)` | [macros](https://sexpgpu.041.io/docs/macros.md) |
| `dotimes` | `(dotimes (i count [result]) body...)` | [control](https://sexpgpu.041.io/docs/control.md) |
| `dolist` | `(dolist (item list [result]) body...)` | [control](https://sexpgpu.041.io/docs/control.md) |
| `multiple-value-bind` | `(multiple-value-bind (names...) expr body...)` | [control](https://sexpgpu.041.io/docs/control.md) |
| `multiple-value-list` | `(multiple-value-list expr)` | [control](https://sexpgpu.041.io/docs/control.md) |
| `multiple-value-call` | `(multiple-value-call f expr...)` | [control](https://sexpgpu.041.io/docs/control.md) |
| `multiple-value-prog1` | `(multiple-value-prog1 expr body...)` | [control](https://sexpgpu.041.io/docs/control.md) |
| `destructuring-bind` | `(destructuring-bind pattern list body...)` | [functions](https://sexpgpu.041.io/docs/functions.md) |
| `macroexpand-1`, `macroexpand` | `(macroexpand form [env])` | [macros](https://sexpgpu.041.io/docs/macros.md) |
| `intern` | `(intern string [env])` | [macros](https://sexpgpu.041.io/docs/macros.md) |

## Definitions

| form | shape | page |
|---|---|---|
| `defun` | `(defun name lambda-list body...)` | [functions](https://sexpgpu.041.io/docs/functions.md) |
| `defmacro` | `(defmacro name macro-lambda-list body...)` | [macros](https://sexpgpu.041.io/docs/macros.md) |
| `defvar` | `(defvar name value)`, once per module | |
| `require` | `(require "module" name...)`, module top level only | [require](https://sexpgpu.041.io/docs/require.md) |

## Experiment

| form | shape | page |
|---|---|---|
| `defmodel` | `(defmodel name lambda-list body... fn)` | [models](https://sexpgpu.041.io/docs/models.md) |
| `defparam` | `(defparam name initializer &key tags numerics)`, inside a model | [models](https://sexpgpu.041.io/docs/models.md) |
| `with-numerics` | `(with-numerics (:sensitivity :high) body...)` | [numerics](https://sexpgpu.041.io/docs/numerics.md) |
| `defoptimizer` | `(defoptimizer name (param grad ctx &key ...) body...)` | [optimizers](https://sexpgpu.041.io/docs/optimizers.md) |
| `defstate` | `(defstate name zero-initializer)`, inside an optimizer | [optimizers](https://sexpgpu.041.io/docs/optimizers.md) |
| `defknobs` | `(defknobs (name default ["doc"])...)` | [knobs](https://sexpgpu.041.io/docs/knobs.md) |
| `defvariant` | `(defvariant name (knob value)...)` | [knobs](https://sexpgpu.041.io/docs/knobs.md) |
| `defsweep` | `(defsweep name [:variant v] (knob [values])...)` | [knobs](https://sexpgpu.041.io/docs/knobs.md) |
| `defeval` | `(defeval name :loader l [:every n] [:batches k])` | [evaluation](https://sexpgpu.041.io/docs/evaluation.md) |
| `defrun` | `(defrun :steps n ...)` | [defrun](https://sexpgpu.041.io/docs/defrun.md) |

Definitions register when their form executes, so a macro can generate any
of them; see [generated declarations](https://sexpgpu.041.io/docs/macros.md#generated-declarations).
The configuration constructors (`loader`, `stage`, `files`, `manifest`,
`field`, `select`, `group`, `named`) are ordinary builtins; see
[builtins](https://sexpgpu.041.io/docs/builtins.md#experiment-constructors).

---

SexpGPU documentation. Every page: https://sexpgpu.041.io/llms.txt
