TermToObjectConverter

Converts a Prolog Term into a JVM/Kotlin value -- the direction opposite to ObjectToTermConverter -- and drives the overload-resolution machinery (OverloadSelector) used to pick the right method/constructor/property to invoke for a given set of Prolog arguments.

A Term can be ambiguous with respect to which JVM/Kotlin type it should become (e.g. a Prolog integer could become a Long, an Int, a Short... or org.gciatto.kt.math.BigInteger): this converter enumerates all the admissibleTypes a term could be converted into, ranks how well each candidate priorityOfConversion fits (lower is better; null means "not admissible"), and exposes mostAdequateType as the best default guess -- which is what the parameterless convert uses.

ObjectRefs and null (via it.unibo.tuprolog.solve.libs.oop.NullRef) convert straightforwardly to their wrapped object (subject to a subtype check against the requested convertInto type); an explicit X as Type expression (it.unibo.tuprolog.solve.libs.oop.OOP.CAST_OPERATOR) or a dealiasing expression $Alias (resolved via the dealiaser passed to of) is honored too.

See also

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract fun admissibleTypes(term: Term): Set<KClass<*>>

Every JVM/Kotlin type term could reasonably be converted into.

Link copied to clipboard
open fun convert(term: Term): Any?

Converts term into an instance of its mostAdequateType.

Link copied to clipboard
abstract fun convertInto(type: KClass<*>, term: Term): Any?

Converts term into an instance of type.

Link copied to clipboard
abstract fun mostAdequateType(term: Term): KClass<*>

The best (lowest-priority-value) type among admissibleTypes for term.

Link copied to clipboard
abstract fun possibleConversions(term: Term): Sequence<Any?>

Eagerly converts term into every one of its admissibleTypes, in priority order.

Link copied to clipboard
abstract fun priorityOfConversion(type: KClass<*>, term: Term): Int?

How well term fits as an instance of type, lower being a better fit, or null if term cannot be converted into type at all. Used by OverloadSelector to rank candidate overloads.