PtcRunner.Lisp.Runtime.Predicates (PtcRunner v0.10.1)

Copy Markdown View Source

Type predicates, numeric predicates, and logic operations for PTC-Lisp runtime.

Provides type checking functions (nil?, string?, map?, etc.) and numeric predicates (zero?, pos?, neg?, even?, odd?).

Summary

Functions

Coerces a value to boolean. nil and false are false, everything else is true.

Composes functions right-to-left. Zero args returns identity. The rightmost function can accept multiple arguments; all others receive a single value.

Returns a function that returns the boolean opposite of f.

Returns a function that always returns value, ignoring any arguments.

Returns a function that checks all values against each predicate. Short-circuits on first falsy result. Always returns true/false.

Returns a function that replaces nil first argument with a default value.

Identity function: returns its argument unchanged. Useful as a default function argument or for composition.

Coerces a string to keyword. Returns keyword unchanged. Returns nil for nil.

Returns a function with some arguments pre-filled. (partial f a b) returns a function that calls f with a, b, plus any additional args.

Convert collection to set

Returns a function that checks all values against each function. Short-circuits on first truthy result, returning the actual value (not boolean).

Returns the type of a value as a keyword.

Convert collection to vector (list)

Functions

associative?(x)

boolean(arg1)

Coerces a value to boolean. nil and false are false, everything else is true.

boolean?(x)

char?(x)

coll?(x)

comp_variadic(fns)

Composes functions right-to-left. Zero args returns identity. The rightmost function can accept multiple arguments; all others receive a single value.

complement(f)

Returns a function that returns the boolean opposite of f.

constantly(value)

Returns a function that always returns value, ignoring any arguments.

counted?(x)

decimal?(x)

distinct_args?(args)

double?(x)

even?(x)

every_pred_variadic(preds)

Returns a function that checks all values against each predicate. Short-circuits on first falsy result. Always returns true/false.

false?(x)

float?(x)

fn?(x)

fnil(f, default)

Returns a function that replaces nil first argument with a default value.

Automatically detects arity of the wrapped function and returns a function with matching arity. Supports plain functions and builtin tuples.

Commonly used with update: (update m :count (fnil inc 0)) or (update m :count (fnil + 0) 5) to provide default values for nil.

Examples

iex> f = PtcRunner.Lisp.Runtime.Predicates.fnil(&Kernel.+/2, 0)
iex> f.(nil, 5)
5
iex> f.(3, 5)
8

iex> f = PtcRunner.Lisp.Runtime.Predicates.fnil(&(&1 + 1), 0)
iex> f.(nil)
1
iex> f.(5)
6

identity(x)

Identity function: returns its argument unchanged. Useful as a default function argument or for composition.

ifn?(x)

indexed?(x)

infinite?(x)

int?(x)

integer?(x)

keyword(k)

Coerces a string to keyword. Returns keyword unchanged. Returns nil for nil.

Validates that the string matches PTC-Lisp keyword character set (letters, digits, -, _, ?, !; must start with a letter). No / (per DIV-13), no spaces, no empty strings, no operator chars.

Uses String.to_existing_atom/1 to avoid atom table pollution from arbitrary runtime strings. Only keywords already known to the VM (from parsed source or BEAM boot) can be created.

  • (keyword "foo") returns :foo (if :foo already exists)
  • (keyword :bar) returns :bar
  • (keyword nil) returns nil
  • (keyword "") raises error
  • (keyword "foo/bar") raises error (violates DIV-13)

keyword?(x)

map?(x)

map_entry?(_)

nan?(x)

nat_int?(x)

neg?(x)

neg_int?(x)

nil?(x)

not_(x)

number?(x)

odd?(x)

partial_variadic(list)

Returns a function with some arguments pre-filled. (partial f a b) returns a function that calls f with a, b, plus any additional args.

pos?(x)

pos_int?(x)

ratio?(x)

rational?(x)

regex?(x)

reversible?(x)

seq?(x)

seqable?(x)

sequential?(x)

set(coll)

Convert collection to set

set?(x)

some?(x)

some_fn_variadic(fns)

Returns a function that checks all values against each function. Short-circuits on first truthy result, returning the actual value (not boolean).

sorted?(_)

string?(x)

symbol?(x)

true?(x)

type_of(x)

Returns the type of a value as a keyword.

vec(coll)

Convert collection to vector (list)

vector?(x)

zero?(x)