AbstractTermificator

abstract class AbstractTermificator(val scope: Scope) : Termificator

Skeletal implementation of Termificator, providing the type-dispatch machinery (termify) and a library of protected handleXxxAsYyy conversion functions that subclasses register (via handleType) to implement Termificator.default/Termificator.legacy and any other custom conversion policy.

Conversions are looked up in converters, a registration-ordered map from KClass to converter function: an exact match on value::class is tried first, then the map is scanned in registration order for the first registered type the converted value is an instance of — so more specific types should be handleType-registered before more general ones (see legacyConfiguration/novelConfiguration for the order this module itself relies on).

A subclass only needs to implement handleNumberAsNumeric (the concrete Number-to-Term policy differs between platforms, e.g. to leverage native BigInteger/BigDecimal types) and call defaultConfiguration — or handleType directly — from its constructor to populate converters.

Constructors

Link copied to clipboard
constructor(scope: Scope)

Properties

Link copied to clipboard
open override val scope: Scope

The Scope backing every Term this Termificator produces.

Functions

Link copied to clipboard
abstract fun copy(scope: Scope = this.scope): Termificator

Creates a copy of this Termificator, backed by scope (defaulting to this one's own scope).

Link copied to clipboard
open override fun termify(value: Any?): Term

Converts value to a Term: returns it unchanged if it already is one, delegates to TermConvertible.toTerm if it is a TermConvertible, otherwise dispatches to the converters registered via handleType (exact runtime type first, then the first registered supertype value is an instance of).