Backtracking fixed
This commit is contained in:
parent
a85169dced
commit
fd16c4cedc
18 changed files with 213 additions and 39 deletions
|
@ -15,19 +15,15 @@ import prolog.ast.terms.*
|
|||
|
||||
// Apply substitutions to a term
|
||||
fun applySubstitution(term: Term, subs: Substitutions): Term = when {
|
||||
term is Fact -> {
|
||||
Fact(applySubstitution(term.head, subs) as Head)
|
||||
}
|
||||
term is Fact -> term.applySubstitution(subs)
|
||||
|
||||
variable(term, emptyMap()) -> {
|
||||
val variable = term as Variable
|
||||
subs[variable]?.let { applySubstitution(term = it, subs = subs) } ?: term
|
||||
}
|
||||
|
||||
atomic(term, subs) -> term
|
||||
compound(term, subs) -> {
|
||||
val structure = term as Structure
|
||||
Structure(structure.name, structure.arguments.map { applySubstitution(it, subs) })
|
||||
}
|
||||
compound(term, subs) -> term.applySubstitution(subs)
|
||||
|
||||
else -> term
|
||||
}
|
||||
|
|
Reference in a new issue