# `PtcRunner.Lisp.Eval.Apply`
[🔗](https://github.com/andreasronge/ptc_runner/blob/main/lib/ptc_runner/lisp/eval/apply.ex#L1)

Function application dispatch for Lisp evaluation.

Handles calling closures, keywords, maps, sets, builtins, and plain functions.

## Supported function types

- Keywords as map accessors: `(:key map)` → `Map.get(map, :key)`
- Maps as keyword accessors: `(map :key)` → `Map.get(map, :key)`
- Sets as membership check: `(set x)` → `x` or `nil`
- Closures: user-defined functions
- Builtins: `{:normal, fun}`, `{:variadic, fun, identity}`, etc.
- Plain Erlang functions

# `apply_fun`

```elixir
@spec apply_fun(term(), [term()], PtcRunner.Lisp.Eval.Context.t(), (term(),
                                                              PtcRunner.Lisp.Eval.Context.t() -&gt;
                                                                {:ok, term(),
                                                                 PtcRunner.Lisp.Eval.Context.t()}
                                                                | {:error,
                                                                   term()})) ::
  {:ok, term(), PtcRunner.Lisp.Eval.Context.t()} | {:error, term()}
```

Applies a function value to a list of arguments.

# `closure_to_fun`

```elixir
@spec closure_to_fun(term(), PtcRunner.Lisp.Eval.Context.t(), (term(),
                                                         PtcRunner.Lisp.Eval.Context.t() -&gt;
                                                           term())) :: term()
```

Converts Lisp closures to Erlang functions for use with higher-order functions.

Creates functions with appropriate arity based on number of patterns.
Also unwraps builtin function tuples.

---

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