Backtracking fixed

This commit is contained in:
Tibo De Peuter 2025-05-05 20:11:44 +02:00
parent a85169dced
commit fd16c4cedc
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
18 changed files with 213 additions and 39 deletions

View file

@ -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
}