PtcRunner.Lisp.Eval.Apply (PtcRunner v0.9.0)

Copy Markdown View Source

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

Summary

Functions

Applies a function value to a list of arguments.

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

Functions

apply_fun(fun_val, args, eval_ctx, do_eval_fn)

@spec apply_fun(term(), [term()], PtcRunner.Lisp.Eval.Context.t(), (term(),
                                                              PtcRunner.Lisp.Eval.Context.t() ->
                                                                {: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(builtin, eval_context, do_eval_fn)

@spec closure_to_fun(term(), PtcRunner.Lisp.Eval.Context.t(), (term(),
                                                         PtcRunner.Lisp.Eval.Context.t() ->
                                                           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.