fix: Evaluation
This commit is contained in:
parent
d702b9b081
commit
1acd1cfb67
17 changed files with 189 additions and 120 deletions
20
src/prolog/builtins/unification.kt
Normal file
20
src/prolog/builtins/unification.kt
Normal file
|
@ -0,0 +1,20 @@
|
|||
package prolog.builtins
|
||||
|
||||
import prolog.components.terms.Atom
|
||||
import prolog.components.terms.Structure
|
||||
import prolog.components.terms.Term
|
||||
import prolog.components.terms.Variable
|
||||
|
||||
/**
|
||||
* True if Term1 is equivalent to Term2. A variable is only identical to a sharing variable.
|
||||
*/
|
||||
fun equivalent(term1: Term, term2: Term): Boolean {
|
||||
return when {
|
||||
term1 is Variable && term2 is Variable -> term1 == term2
|
||||
term1 is Variable -> term1.alias().isPresent && equivalent(term1.alias().get(), term2)
|
||||
term2 is Variable -> term2.alias().isPresent && equivalent(term2.alias().get(), term1)
|
||||
term1 is Atom && term2 is Atom -> term1.compareTo(term2) == 0
|
||||
term1 is Structure && term2 is Structure -> term1.compareTo(term2) == 0
|
||||
else -> false
|
||||
}
|
||||
}
|
Reference in a new issue