Call & Ignore
This commit is contained in:
parent
9b454a9669
commit
5bfeb96176
7 changed files with 118 additions and 28 deletions
|
@ -3,6 +3,7 @@ package interpreter
|
|||
import io.Logger
|
||||
import prolog.ast.arithmetic.Expression
|
||||
import prolog.ast.arithmetic.Integer
|
||||
import prolog.ast.lists.List as PList
|
||||
import prolog.ast.logic.Clause
|
||||
import prolog.ast.logic.Fact
|
||||
import prolog.ast.logic.LogicOperand
|
||||
|
@ -50,9 +51,9 @@ open class Preprocessor {
|
|||
protected open fun preprocess(term: Term, nested: Boolean = false): Term {
|
||||
// TODO Remove hardcoding by storing the functors as constants in operators?
|
||||
|
||||
val prepped = when {
|
||||
term == Variable("_") -> AnonymousVariable.create()
|
||||
term is Atom || term is Structure -> {
|
||||
val prepped = when (term) {
|
||||
Variable("_") -> AnonymousVariable.create()
|
||||
is Atom, is Structure -> {
|
||||
// Preprocess the arguments first to recognize builtins
|
||||
val args = if (term is Structure) {
|
||||
term.arguments.map { preprocess(it, nested = true) }
|
||||
|
@ -149,6 +150,13 @@ open class Preprocessor {
|
|||
Functor.of("nl/0") -> Nl
|
||||
Functor.of("read/1") -> Read(args[0])
|
||||
|
||||
// Lists
|
||||
Functor.of("member/2") -> Member(args[0], args[1] as PList)
|
||||
|
||||
// Meta
|
||||
Functor.of("call/1") -> Call(args[0] as Goal)
|
||||
Functor.of("ignore/1") -> Ignore(args[0] as Goal)
|
||||
|
||||
// Other
|
||||
Functor.of("initialization/1") -> Initialization(args[0] as Goal)
|
||||
Functor.of("forall/2") -> ForAll(args[0] as LogicOperand, args[1] as Goal)
|
||||
|
|
Reference in a new issue