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
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.
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 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.
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:fooalready exists)(keyword :bar)returns:bar(keyword nil)returnsnil(keyword "")raises error(keyword "foo/bar")raises error (violates DIV-13)
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)