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

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.

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.

Convert collection to set

Returns the type of a value as a keyword.

Convert collection to vector (list)

Functions

boolean(arg1)

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

boolean?(x)

char?(x)

coll?(x)

even?(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.

keyword?(x)

map?(x)

neg?(x)

nil?(x)

not_(x)

number?(x)

odd?(x)

pos?(x)

regex?(x)

seq?(x)

sequential?(x)

set(coll)

Convert collection to set

set?(x)

some?(x)

string?(x)

type_of(x)

Returns the type of a value as a keyword.

vec(coll)

Convert collection to vector (list)

vector?(x)

zero?(x)