Skip to content

Commit

Permalink
restore & correct type tests in Struct
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed Jun 28, 2021
1 parent aa6d7d7 commit fb9f596
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions core/src/commonMain/kotlin/it/unibo/tuprolog/core/Struct.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package it.unibo.tuprolog.core

import it.unibo.tuprolog.core.Terms.CLAUSE_FUNCTOR
import it.unibo.tuprolog.core.Terms.CONS_FUNCTOR
import it.unibo.tuprolog.core.Terms.EMPTY_LIST_FUNCTOR
import it.unibo.tuprolog.core.Terms.EMPTY_SET_FUNCTOR
import it.unibo.tuprolog.core.Terms.FAIL_FUNCTOR
import it.unibo.tuprolog.core.Terms.INDICATOR_FUNCTOR
import it.unibo.tuprolog.core.Terms.SET_FUNCTOR
import it.unibo.tuprolog.core.Terms.TRUE_FUNCTOR
import it.unibo.tuprolog.core.Terms.TUPLE_FUNCTOR
import it.unibo.tuprolog.core.impl.StructImpl
import kotlin.js.JsName
Expand All @@ -21,6 +25,52 @@ interface Struct : Term {
override val isStruct: Boolean
get() = true

override val isClause: Boolean
get() = CLAUSE_FUNCTOR == functor && when (arity) {
2 -> getArgAt(0).isStruct
1 -> true
else -> false
}

override val isRule: Boolean
get() = isClause && arity == 2

override val isDirective: Boolean
get() = isClause && arity == 1

override val isFact: Boolean
get() = isRule && getArgAt(1).isTrue

override val isTuple: Boolean
get() = functor == TUPLE_FUNCTOR && arity == 2

override val isAtom: Boolean
get() = arity == 0

override val isList: Boolean
get() = isCons || isEmptyList

override val isCons: Boolean
get() = CONS_FUNCTOR == functor && arity == 2

override val isSet: Boolean
get() = (SET_FUNCTOR == functor && arity == 1) || isEmptySet

override val isEmptySet: Boolean
get() = EMPTY_SET_FUNCTOR == functor && arity == 0

override val isEmptyList: Boolean
get() = EMPTY_LIST_FUNCTOR == functor && arity == 0

override val isTrue: Boolean
get() = isAtom && TRUE_FUNCTOR == functor

override val isFail: Boolean
get() = isAtom && FAIL_FUNCTOR == functor

override val isIndicator: Boolean
get() = Indicator.FUNCTOR == functor && arity == 2

override val variables: Sequence<Var>
get() = argsSequence.flatMap { it.variables }

Expand Down

0 comments on commit fb9f596

Please sign in to comment.