Type predicates and helpers

koskari.types

Koskari native types, predicates, and helper functions

class koskari.types.BuiltinPredicate(name, call, *args, **kwds)

Bases: partial

A predicate function that tests an object using a callable.

class koskari.types.TypePredicate(name, typeobj)

Bases: partial

A predicate function that tests whether an object is an instance of a particular type.

koskari.types.bracket_splice(*segments)

The bracket analogue of the PAIR_SPLICE opcode: flatten the given segments (pairs, tuples, nil, or other iterables) into a single list whose leading cell is a bracket-pair. Only the head needs to be a bracket cell — repr is governed by the leading cell — so the tail stays plain pairs and no full-spine copy is made. An empty result is bracket-nil.

Parameters:

segments – the splice segments to concatenate

Returns:

the spliced bracket list

koskari.types.build_proper(*values)

Create a proper list from the given values.

Parameters:

values – the values to include in the list

Returns:

a proper list, or nil if no values given

koskari.types.is_None(b, /)

Same as a is b.

koskari.types.is_const(value)

Returns True if value is constant-pool material: exactly one of the CONST_TYPES, or exactly a tuple or frozenset of such values. A subclass is refused, since the pool keeps only its builtin kind

koskari.types.is_nil(object, /)

nilp(value) -> bool True if value is an empty-list singleton (nil or bracket-nil).

async koskari.types.is_on_demand()

Return True if the current execution context is a demand context.

Probes by attempting a single suspension. If running under demand_call or demand(fn), KoskariSyncViolation is thrown into the coroutine at the yield point and caught here, returning True. If running normally (event loop or top-level async), the suspension succeeds and the function returns False.

Intended for Python library code that needs to choose a code path based on whether it is being called from a demand context.

koskari.types.is_proper(value)

Returns True if value is a proper list (a pair terminated by nil).

koskari.types.is_recursive(value)

Returns True if value is a recursive (circular) pair structure.

koskari.types.parameterize(mapping=None, /, **bindings)

Bind parameters for the extent of a Python block.

The Python-side counterpart of the koskari parameterize special. Inside the block a read of each named parameter, from Python or from koskari code called within it, sees the bound value; at exit the prior binding answers again. A koskari context, coroutine or asyncio task created inside the block keeps the bindings applied at its creation. Blocks belong to the running stack: a thread’s synchronous stack, or one asyncio task.

Parameters:
  • mapping – parameter names (str or symbol) to values, for names that are not Python identifiers

  • bindings – parameter names to values

Returns:

the context manager

koskari.types.strip_mark(value)

The base symbol of a gensym, or value unchanged. Use where an atom is read as a tag, a label, or a literal: hygiene renames only the names a form binds and resolves

koskari.types.strip_marks(form)

A copy of a form with every gensym replaced by its base symbol. Pair cells are rebuilt with their positions and delimiter style; atoms other than gensyms are returned as they are

koskari.types.unpack(value)

Return an iterator over the elements of value.

If value is a pair, returns its unpack iterator. Otherwise, returns iter(value).

Parameters:

value – a pair or other iterable

Returns:

an iterator