Checkpoint
This commit is contained in:
parent
39c3af4ba5
commit
da21d890fb
39 changed files with 1166 additions and 48 deletions
41
src/prolog/builtins/verification.kt
Normal file
41
src/prolog/builtins/verification.kt
Normal file
|
@ -0,0 +1,41 @@
|
|||
package prolog.builtins
|
||||
|
||||
import prolog.components.terms.CompoundTerm
|
||||
import prolog.components.terms.Term
|
||||
import prolog.components.terms.Variable
|
||||
|
||||
/**
|
||||
* True if [Term] is bound (i.e., not a variable) and is not compound.
|
||||
* Thus, atomic acts as if defined by:
|
||||
*
|
||||
* atomic(Term) :-
|
||||
* nonvar(Term),
|
||||
* \+ compound(Term).
|
||||
*/
|
||||
fun atomic(term: Term): Boolean = nonvariable(term) && !compound(term)
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
val isCompound = term is CompoundTerm
|
||||
val isVariableCompound = term is Variable && term.alias().isPresent && compound(term.alias().get())
|
||||
return isCompound || isVariableCompound
|
||||
}
|
||||
|
||||
/**
|
||||
* True if [Term] currently is not a free variable.
|
||||
*/
|
||||
fun nonvariable(term: Term): Boolean = !variable(term)
|
||||
|
||||
/**
|
||||
* True if [Term] currently is a free variable.
|
||||
*/
|
||||
fun variable(term: Term): Boolean {
|
||||
if (term is Variable) {
|
||||
return term.alias().isEmpty || term.alias().get() === term || variable(term.alias().get())
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
Reference in a new issue