refactor: Herstructurering
This commit is contained in:
parent
1acd1cfb67
commit
e3c84e1761
33 changed files with 290 additions and 178 deletions
1
src/prolog/builtins/arithmetic.kt
Normal file
1
src/prolog/builtins/arithmetic.kt
Normal file
|
@ -0,0 +1 @@
|
|||
package prolog.builtins
|
|
@ -1,15 +1,12 @@
|
|||
package prolog.builtins
|
||||
|
||||
import prolog.Substituted
|
||||
import prolog.components.expressions.Operand
|
||||
import prolog.components.expressions.Operator
|
||||
import prolog.components.terms.Atom
|
||||
import prolog.components.terms.Body
|
||||
import prolog.ast.terms.*
|
||||
import prolog.logic.Substituted
|
||||
|
||||
/**
|
||||
* Always fail.
|
||||
*/
|
||||
class Fail: Atom("fail"), Body {
|
||||
class Fail : Atom("fail"), Body {
|
||||
override fun prove(subs: Substituted): Sequence<Substituted> = emptySequence()
|
||||
}
|
||||
|
||||
|
@ -21,7 +18,7 @@ typealias False = Fail
|
|||
/**
|
||||
* Always succeed.
|
||||
*/
|
||||
class True: Atom("true"), Body {
|
||||
class True : Atom("true"), Body {
|
||||
override fun prove(subs: Substituted): Sequence<Substituted> = sequenceOf(emptyMap())
|
||||
}
|
||||
|
||||
|
@ -49,7 +46,7 @@ class Conjunction(leftOperand: Operand, rightOperand: Operand) : Operator(Atom("
|
|||
/**
|
||||
* Disjunction (or). True if either Goal1 or Goal2 succeeds.
|
||||
*/
|
||||
class Disjunction(leftOperand: Operand, rightOperand: Operand) : Operator(Atom(";"), leftOperand, rightOperand) {
|
||||
open class Disjunction(leftOperand: Operand, rightOperand: Operand) : Operator(Atom(";"), leftOperand, rightOperand) {
|
||||
override fun prove(subs: Substituted): Sequence<Substituted> = sequence {
|
||||
if (leftOperand != null) {
|
||||
yieldAll(leftOperand.prove(subs))
|
||||
|
@ -57,3 +54,24 @@ class Disjunction(leftOperand: Operand, rightOperand: Operand) : Operator(Atom("
|
|||
yieldAll(rightOperand.prove(subs))
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Use Disjunction instead")
|
||||
class Bar(leftOperand: Operand, rightOperand: Operand) : Disjunction(leftOperand, rightOperand)
|
||||
|
||||
// TODO ->
|
||||
|
||||
// TODO *->
|
||||
|
||||
/**
|
||||
* True if 'Goal' cannot be proven.
|
||||
*/
|
||||
class Not(goal: Goal) : Operator(Atom("\\+"), rightOperand = goal) {
|
||||
override fun prove(subs: Substituted): Sequence<Substituted> {
|
||||
// If the goal can be proven, return an empty sequence
|
||||
if (rightOperand.prove(subs).toList().isNotEmpty()) {
|
||||
return emptySequence()
|
||||
}
|
||||
// If the goal cannot be proven, return a sequence with an empty map
|
||||
return sequenceOf(emptyMap())
|
||||
}
|
||||
}
|
||||
|
|
1
src/prolog/builtins/meta.kt
Normal file
1
src/prolog/builtins/meta.kt
Normal file
|
@ -0,0 +1 @@
|
|||
package prolog.builtins
|
|
@ -1,9 +1,9 @@
|
|||
package prolog.builtins
|
||||
|
||||
import prolog.Substituted
|
||||
import prolog.components.expressions.Operand
|
||||
import prolog.components.expressions.Operator
|
||||
import prolog.components.terms.Atom
|
||||
import prolog.ast.terms.Atom
|
||||
import prolog.ast.terms.Operand
|
||||
import prolog.ast.terms.Operator
|
||||
import prolog.logic.Substituted
|
||||
|
||||
class Query(rightOperand: Operand) : Operator(Atom("?-"), null, rightOperand) {
|
||||
override fun prove(subs: Substituted): Sequence<Substituted> = rightOperand.prove(subs)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package prolog.builtins
|
||||
|
||||
import prolog.components.terms.Atom
|
||||
import prolog.components.terms.Term
|
||||
import prolog.ast.terms.Atom
|
||||
import prolog.ast.terms.Term
|
||||
|
||||
/**
|
||||
* True when Term is a term with functor Name/Arity. If Term is a variable it is unified with a new term whose
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package prolog.builtins
|
||||
|
||||
import prolog.components.terms.Atom
|
||||
import prolog.components.terms.Structure
|
||||
import prolog.components.terms.Term
|
||||
import prolog.components.terms.Variable
|
||||
import prolog.ast.terms.Atom
|
||||
import prolog.ast.terms.Structure
|
||||
import prolog.ast.terms.Term
|
||||
import prolog.ast.terms.Variable
|
||||
|
||||
/**
|
||||
* True if Term1 is equivalent to Term2. A variable is only identical to a sharing variable.
|
||||
|
@ -18,3 +18,7 @@ fun equivalent(term1: Term, term2: Term): Boolean {
|
|||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package prolog.builtins
|
||||
|
||||
import prolog.components.terms.CompoundTerm
|
||||
import prolog.components.terms.Term
|
||||
import prolog.components.terms.Variable
|
||||
import prolog.ast.terms.CompoundTerm
|
||||
import prolog.ast.terms.Term
|
||||
import prolog.ast.terms.Variable
|
||||
|
||||
/**
|
||||
* True if [Term] is bound (i.e., not a variable) and is not compound.
|
||||
|
|
Reference in a new issue