PtcRunner.Lisp.Analyze.Conditionals (PtcRunner v0.10.1)

Copy Markdown View Source

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.

Summary

Functions

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

Analyzes a cond form. Desugars to nested if expressions.

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

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

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

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

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

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

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

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

Functions

analyze_case(list, tail?, analyze_fn, wrap_body_fn)

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(args, tail?, analyze_fn, wrap_body_fn)

Analyzes a cond form. Desugars to nested if expressions.

analyze_condp(args, tail?, analyze_fn, wrap_body_fn)

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(arg1, tail?, analyze_fn, wrap_body_fn)

Analyzes an if form.

analyze_if_let(arg1, tail?, analyze_fn, wrap_body_fn)

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

analyze_if_not(arg1, tail?, analyze_fn, wrap_body_fn)

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

analyze_if_some(arg1, tail?, analyze_fn, wrap_body_fn, mark_shadow_fn)

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(arg1, tail?, analyze_fn, wrap_body_fn)

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

analyze_when_first(arg1, tail?, analyze_fn, wrap_body_fn, mark_shadow_fn)

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(arg1, tail?, analyze_fn, wrap_body_fn)

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

analyze_when_not(arg1, tail?, analyze_fn, wrap_body_fn)

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

analyze_when_some(arg1, tail?, analyze_fn, wrap_body_fn, mark_shadow_fn)

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.