Interfaces

Basilisp (like Clojure) is defined by interfaces. All of the built-in data types are implement 0 or more of these Python interfaces and basilisp.core functions typically operate on these interfaces, rather than concrete data types (with some exceptions).

In day-to-day usage, you will not typically need to use these interfaces, but they are nevertheless helpful for understanding the abstractions Basilisp is built upon.

Warning

These interfaces are not considered part of the Basilisp public API and therefore are subject to change at any time without notice. This documentation is intended to help users understand the abstractions that underpin Basilisp.

class basilisp.lang.interfaces.ILispObject

Abstract base class for Lisp objects which would like to customize their __str__ and Python __repr__ representation.

abstract ILispObject._lrepr(**kwargs: Unpack[PrintSettings]) str

Private Lisp representation method. Callers (including object internal callers) should not call this method directly, but instead should use the module function lrepr() .

ILispObject.lrepr(**kwargs: Unpack[PrintSettings]) str

Return a string representation of this Lisp object which can be read by the reader.

class basilisp.lang.interfaces.IAssociative

Bases: ILookup[K, V], IPersistentCollection[IMapEntry[K, V]]

IAssociative types support a persistent data structure variant of associative operations.

abstract assoc(*kvs) Self
abstract contains(k: K) bool
abstract entry(k: K) IMapEntry[K, V] | None
class basilisp.lang.interfaces.IBlockingDeref

Bases: IDeref[T]

IBlockingDeref types are reference container types which may block returning their contained value. The contained value can be fetched with a timeout and default via deref .

See also

IDeref

abstract deref(timeout: float | None = None, timeout_val: T | None = None) T | None
class basilisp.lang.interfaces.ICounted

Bases: Sized, ABC

ICounted is a marker interface for types can produce their length in constant time.

All the builtin collections are ICounted, except Lists whose length is determined by counting all the elements in the list in linear time.

See also

counted?

class basilisp.lang.interfaces.IDeref

Bases: Generic[T], ABC

IDeref types are reference container types which return their contained value via deref .

See also

IBlockingDeref

abstract deref() T | None
class basilisp.lang.interfaces.IEvolveableCollection

Bases: Generic[T_tcoll_co]

IEvolveableCollection types support creating transient variants of persistent data structures which can be modified efficiently and then returned back into persistent data structures once modification is complete.

See also

transient

abstract to_transient() T_tcoll_co
exception basilisp.lang.interfaces.IExceptionInfo

Bases: Exception, Generic[T_ExceptionInfo], ABC

IExceptionInfo types are exception types which contain an optional IPersistentMap data element of contextual information about the thrown exception.

See also

ex-data

abstract property data: T_ExceptionInfo
class basilisp.lang.interfaces.IIndexed

Bases: ICounted, ABC

IIndexed is a marker interface for types can be accessed by index.

Of the builtin collections, only Vectors are IIndexed . IIndexed types respond True to the indexed? predicate.

See also

indexed?

class basilisp.lang.interfaces.ILookup

Bases: Generic[K, V], ABC

ILookup types allow accessing contained values by a key or index.

See also

get

abstract val_at(k: K, default: V | None = None) V | None
class basilisp.lang.interfaces.IMapEntry

Bases: Generic[K, V], ABC

IMapEntry values are produced seq ing over any IAssociative (such as a Basilisp map).

See also

key , val , map-entry?

abstract property key: K
abstract property value: V
class basilisp.lang.interfaces.IMeta

Bases: ABC

IMeta types can optionally include a map of metadata.

Persistent data types metadata cannot be mutated, but many of these data types also implement IWithMeta which allows creating a copy of the structure with new metadata.

See also

meta

abstract property meta: IPersistentMap | None
class basilisp.lang.interfaces.INamed

Bases: ABC

INamed instances are symbolic identifiers with a name and optional namespace.

See also

name , namespace

abstract property name: str
abstract property ns: str | None
abstract classmethod with_name(name: str, ns: str | None = None) Self

Create a new instance of this INamed with name and optional ns.

class basilisp.lang.interfaces.IPersistentCollection

Bases: ISeqable[T]

IPersistentCollection types support both fetching empty variants of an existing persistent collection and creating a new collection with additional members.

See also

conj , empty , coll?

abstract cons(*elems: T) Self
abstract static empty() IPersistentCollection[T]
class basilisp.lang.interfaces.IPersistentList

Bases: ISequential, IPersistentStack[T]

IPersistentList is a marker interface for a singly-linked list.

class basilisp.lang.interfaces.IPersistentMap

Bases: ICounted, Mapping[K, V], IAssociative[K, V]

IPersistentMap types support creating and modifying persistent maps.

See also

conj , dissoc , map?

abstract cons(*elems: IMapEntry[K, V] | IPersistentMap[K, V] | None) Self
abstract dissoc(*ks: K) Self
class basilisp.lang.interfaces.IPersistentSet

Bases: AbstractSet[T], ICounted, IPersistentCollection[T]

IPersistentSet types support creating and modifying persistent sets.

See also

disj , set?

abstract disj(*elems: T) Self
class basilisp.lang.interfaces.IPersistentStack

Bases: IPersistentCollection[T]

IPersistentStack types support a persistent data structure variant of classical stack operations.

See also

pop , peek

abstract peek() T | None
abstract pop() Self
class basilisp.lang.interfaces.IPersistentVector

Bases: Sequence[T], IAssociative[int, T], IIndexed, IReversible[T], ISequential, IPersistentStack[T]

IPersistentVector types support creating and modifying persistent vectors.

See also

vector?

abstract assoc(*kvs) Self
abstract cons(*elems: T) Self
abstract seq() ISeq[T] | None
class basilisp.lang.interfaces.IRecord

Bases: LispObject

IRecord is a marker interface for types def ‘ed by defrecord forms.

All types created by defrecord are automatically marked with IRecord.

abstract classmethod create(m: IPersistentMap) IRecord

Class method constructor from an IPersistentMap instance.

class basilisp.lang.interfaces.IRef

Bases: IDeref[T]

IRef types are mutable reference containers which support validation of the contained value and watchers which are notified when the contained value changes.

abstract add_watch(k: Hashable, wf: Callable[[Hashable, IRef, T, T], None]) IReference
abstract get_validator() Callable[[T], bool] | None
abstract remove_watch(k: Hashable) IReference
abstract set_validator(vf: Callable[[T], bool] | None = None) None
class basilisp.lang.interfaces.IReference

Bases: IMeta

IReference types are mutable reference containers which allow mutation of the associated metadata.

abstract alter_meta(f: Callable[[...], IPersistentMap | None], *args) IPersistentMap | None
abstract reset_meta(meta: IPersistentMap | None) IPersistentMap | None
class basilisp.lang.interfaces.IReversible

Bases: Generic[T]

IReversible types can produce a sequences of their elements in reverse in constant time.

Of the builtin collections, only Vectors are IReversible.

See also

reversible?

abstract rseq() ISeq[T]
class basilisp.lang.interfaces.ISeq

Bases: LispObject, IPersistentCollection[T]

ISeq types represent a potentially infinite sequence of elements.

See also

Seqs , lazy-seq , seq , first , rest , next , second , seq? , nfirst , fnext , nnext , empty? , seq?

abstract cons(*elem: T) ISeq[T]
abstract property first: T | None
abstract property is_empty: bool
abstract property rest: ISeq[T]
seq() ISeq[T] | None
class basilisp.lang.interfaces.ISeqable

Bases: Iterable[T]

ISeqable types can produce sequences of their elements, but are not ISeq .

All the builtin collections are ISeqable, except Lists which directly implement ISeq .

See also

Seqs , seq , seqable?

abstract seq() ISeq[T] | None
class basilisp.lang.interfaces.ISequential

Bases: ABC

ISequential is a marker interface for sequential types.

Lists and Vectors are both considered ISequential.

See also

sequential?

class basilisp.lang.interfaces.ITransientAssociative

Bases: ILookup[K, V], ITransientCollection[IMapEntry[K, V]]

ITransientAssociative types are the transient counterpart of IAssociative types.

See also

assoc! , contains?, find

abstract assoc_transient(*kvs) Self
abstract contains_transient(k: K) bool
abstract entry_transient(k: K) IMapEntry[K, V] | None
class basilisp.lang.interfaces.ITransientCollection

Bases: Generic[T]

ITransientCollection types support efficient modification of otherwise persistent data structures.

See also

conj! , persistent!

abstract cons_transient(*elems: T) T_tcoll_co
abstract to_persistent() IPersistentCollection[T]
class basilisp.lang.interfaces.ITransientMap

Bases: ICounted, ITransientAssociative[K, V]

ITransientMap types are the transient counterpart of IPersistentMap types.

See also

dissoc!

abstract cons_transient(*elems: IMapEntry[K, V] | IPersistentMap[K, V] | None) Self
abstract dissoc_transient(*ks: K) Self
class basilisp.lang.interfaces.ITransientSet

Bases: ICounted, ITransientCollection[T]

ITransientSet types are the transient counterpart of IPersistentSet types.

See also

disj!

abstract disj_transient(*elems: T) Self
class basilisp.lang.interfaces.ITransientVector

Bases: ITransientAssociative[int, T], IIndexed

ITransientVector types are the transient counterpart of IPersistentVector types.

abstract assoc_transient(*kvs) T_tvec
abstract cons_transient(*elems: T) T_tvec
abstract pop_transient() T_tvec
class basilisp.lang.interfaces.IType

Bases: ABC

IType is a marker interface for types def ‘ed by deftype forms.

All types created by deftype are automatically marked with IType.

class basilisp.lang.interfaces.IWithMeta

Bases: IMeta

IWithMeta are IMeta types which can create copies of themselves with new metadata.

See also

with-meta

abstract with_meta(meta: IPersistentMap | None) Self