refactor: Rework
This commit is contained in:
parent
ac55ed4c64
commit
6469dd6ced
34 changed files with 593 additions and 552 deletions
|
@ -1,5 +1,6 @@
|
|||
package prolog.logic
|
||||
|
||||
import prolog.Substitutions
|
||||
import prolog.ast.terms.CompoundTerm
|
||||
import prolog.ast.terms.Term
|
||||
import prolog.ast.terms.Variable
|
||||
|
@ -12,29 +13,29 @@ import prolog.ast.terms.Variable
|
|||
* nonvar(Term),
|
||||
* \+ compound(Term).
|
||||
*/
|
||||
fun atomic(term: Term): Boolean = nonvariable(term) && !compound(term)
|
||||
fun atomic(term: Term, subs: Substitutions = emptyMap()): Boolean = nonvariable(term, subs) && !compound(term, subs)
|
||||
|
||||
/**
|
||||
* True if [Term] is bound to a compound term.
|
||||
* See also functor/3 =../2, compound_name_arity/3 and compound_name_arguments/3.
|
||||
*/
|
||||
fun compound(term: Term): Boolean {
|
||||
fun compound(term: Term, subs: Substitutions = emptyMap()): Boolean {
|
||||
val isCompound = term is CompoundTerm
|
||||
val isVariableCompound = term is Variable && term.alias().isPresent && compound(term.alias().get())
|
||||
val isVariableCompound = term is Variable && term in subs && compound(subs[term]!!, subs)
|
||||
return isCompound || isVariableCompound
|
||||
}
|
||||
|
||||
/**
|
||||
* True if [Term] currently is not a free variable.
|
||||
*/
|
||||
fun nonvariable(term: Term): Boolean = !variable(term)
|
||||
fun nonvariable(term: Term, subs: Substitutions = emptyMap()): Boolean = !variable(term, subs)
|
||||
|
||||
/**
|
||||
* True if [Term] currently is a free variable.
|
||||
*/
|
||||
fun variable(term: Term): Boolean {
|
||||
fun variable(term: Term, subs: Substitutions = emptyMap()): Boolean {
|
||||
if (term is Variable) {
|
||||
return term.alias().isEmpty || term.alias().get() === term || variable(term.alias().get())
|
||||
return term !in subs || subs[term] === term || variable(subs[term]!!, subs)
|
||||
}
|
||||
|
||||
return false
|
||||
|
|
Reference in a new issue