All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.it.unibo.tuprolog.solve.flags.NotableFlag.kt Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.solve.flags

import it.unibo.tuprolog.core.Term
import kotlin.js.JsName
import kotlin.jvm.JvmStatic

interface NotableFlag {
    @JsName("name")
    val name: String

    @JsName("defaultValue")
    val defaultValue: Term

    @JsName("isEditable")
    val isEditable: Boolean
        get() = true

    @JsName("admissibleValues")
    val admissibleValues: Sequence

    @JsName("isAdmissibleValue")
    fun isAdmissibleValue(value: Term): Boolean = value in admissibleValues

    @JsName("toPair")
    fun toPair(): Pair = this to defaultValue

    @JsName("to")
    infix fun to(value: Term): Pair =
        name to
            value.also {
                require(isAdmissibleValue(it)) {
                    "$value is not an admissible value for flag $name"
                }
            }

    companion object {
        @JsName("fromName")
        @JvmStatic
        fun fromName(name: String): NotableFlag? =
            sequenceOf(
                DoubleQuotes,
                LastCallOptimization,
                MaxArity,
                Unknown,
            ).firstOrNull { it.name == name }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy