# `PtcRunner.Lisp.Analyze.Conditionals`
[🔗](https://github.com/andreasronge/ptc_runner/blob/main/lib/ptc_runner/lisp/analyze/conditionals.ex#L1)

Conditional analysis for `if`, `if-not`, `when`, `when-not`, `if-let`,
`when-let`, `if-some`, `when-some`, `when-first`, `cond`, `case`, and `condp` forms.

Transforms conditional expressions into CoreAST `{:if, ...}` nodes,
using callback functions for analyzing sub-expressions and wrapping bodies.

# `analyze_case`

Analyzes a `case` form. Desugars to a let binding + nested `if` with equality checks.

Test values must be compile-time constants (keywords, strings, numbers, booleans, nil).
Grouped values `(:a :b)` match any value in the group.
Returns nil if no match and no default.

# `analyze_cond`

Analyzes a `cond` form. Desugars to nested `if` expressions.

# `analyze_condp`

Analyzes a `condp` form. Desugars to let bindings + nested `if` with predicate calls.

Calls `(pred test-val expr)` for each clause. Both pred and expr are evaluated exactly once.
Returns nil if no match and no default.
The `:>>` form is not supported.

# `analyze_if`

Analyzes an `if` form.

# `analyze_if_let`

Analyzes an `if-let` form. Desugars to `(let [x cond] (if x then else))`.

# `analyze_if_not`

Analyzes an `if-not` form. Desugars by swapping then/else branches.

# `analyze_if_some`

Analyzes an `if-some` form. Desugars to `(let [x expr] (if (nil? x) else then))`.

Unlike `if-let`, `if-some` only tests for nil — `false` binds successfully.

# `analyze_when`

Analyzes a `when` form. Desugars to `(if cond (do body...) nil)`.

# `analyze_when_first`

Analyzes a `when-first` form.

Desugars to:
    (let [__wf (seq coll)]
      (if (nil? __wf)
        nil
        (let [x (first __wf)]
          (do body...))))

Binds `coll` once via `seq` to avoid double evaluation, then binds the
first element if the sequence is non-empty.

# `analyze_when_let`

Analyzes a `when-let` form. Desugars to `(let [x cond] (if x body nil))`.

# `analyze_when_not`

Analyzes a `when-not` form. Desugars to `(if cond nil (do body...))`.

# `analyze_when_some`

Analyzes a `when-some` form. Desugars to `(let [x expr] (if (nil? x) nil (do body...)))`.

Unlike `when-let`, `when-some` only tests for nil — `false` binds successfully.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
