Functor
This commit is contained in:
parent
dff53b4e68
commit
65c4d925d3
15 changed files with 270 additions and 83 deletions
|
@ -67,51 +67,51 @@ open class Preprocessor {
|
|||
when {
|
||||
// TODO Remove hardcoding by storing the functors as constants in operators?
|
||||
|
||||
term.functor == ":-/2" -> Rule( args[0] as Head, args[1] as Body )
|
||||
term.functor == FunctorInfo.of(":-/2") -> Rule( args[0] as Head, args[1] as Body )
|
||||
|
||||
// Logic
|
||||
term.functor == "=/2" -> Unify(args[0], args[1])
|
||||
term.functor == "\\=/2" -> NotUnify(args[0], args[1])
|
||||
term.functor == ",/2" -> Conjunction(args[0] as LogicOperand, args[1] as LogicOperand)
|
||||
term.functor == ";/2" -> Disjunction(args[0] as LogicOperand, args[1] as LogicOperand)
|
||||
term.functor == "\\+/1" -> Not(args[0] as Goal)
|
||||
term.functor == "\\==/2" -> NotEquivalent(args[0], args[1])
|
||||
term.functor == "==/2" -> Equivalent(args[0], args[1])
|
||||
term.functor == FunctorInfo.of("=/2") -> Unify(args[0], args[1])
|
||||
term.functor == FunctorInfo.of("\\=/2") -> NotUnify(args[0], args[1])
|
||||
term.functor == FunctorInfo.of(",/2") -> Conjunction(args[0] as LogicOperand, args[1] as LogicOperand)
|
||||
term.functor == FunctorInfo.of(";/2") -> Disjunction(args[0] as LogicOperand, args[1] as LogicOperand)
|
||||
term.functor == FunctorInfo.of("\\+/1") -> Not(args[0] as Goal)
|
||||
term.functor == FunctorInfo.of("\\==/2") -> NotEquivalent(args[0], args[1])
|
||||
term.functor == FunctorInfo.of("==/2") -> Equivalent(args[0], args[1])
|
||||
|
||||
term.functor == "=\\=/2" && args.all { it is Expression } -> EvaluatesToDifferent(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == "=:=/2" && args.all { it is Expression } -> EvaluatesTo(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == "is/2" && args.all { it is Expression } -> Is(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == FunctorInfo.of("=\\=/2") && args.all { it is Expression } -> EvaluatesToDifferent(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == FunctorInfo.of("=:=/2") && args.all { it is Expression } -> EvaluatesTo(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == FunctorInfo.of("is/2") && args.all { it is Expression } -> Is(args[0] as Expression, args[1] as Expression)
|
||||
|
||||
// Arithmetic
|
||||
|
||||
term.functor == "-/1" && args.all { it is Expression } -> Negate(args[0] as Expression)
|
||||
term.functor == "-/2" && args.all { it is Expression } -> Subtract(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == "+/1" && args.all { it is Expression } -> Positive(args[0] as Expression)
|
||||
term.functor == "+/2" && args.all { it is Expression } -> Add(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == "*/2" && args.all { it is Expression } -> Multiply(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == "//2" && args.all { it is Expression } -> Divide(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == "between/3" && args.all { it is Expression } -> Between(args[0] as Expression, args[1] as Expression, args[2] as Expression)
|
||||
term.functor == "succ/2" && args.all { it is Expression } -> Successor(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == FunctorInfo.of("-/1") && args.all { it is Expression } -> Negate(args[0] as Expression)
|
||||
term.functor == FunctorInfo.of("-/2") && args.all { it is Expression } -> Subtract(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == FunctorInfo.of("+/1") && args.all { it is Expression } -> Positive(args[0] as Expression)
|
||||
term.functor == FunctorInfo.of("+/2") && args.all { it is Expression } -> Add(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == FunctorInfo.of("*/2") && args.all { it is Expression } -> Multiply(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == FunctorInfo.of("//2") && args.all { it is Expression } -> Divide(args[0] as Expression, args[1] as Expression)
|
||||
term.functor == FunctorInfo.of("between/3") && args.all { it is Expression } -> Between(args[0] as Expression, args[1] as Expression, args[2] as Expression)
|
||||
term.functor == FunctorInfo.of("succ/2") && args.all { it is Expression } -> Successor(args[0] as Expression, args[1] as Expression)
|
||||
|
||||
// Database
|
||||
term.functor == "dynamic/1" -> Dynamic((args[0] as Atom).name)
|
||||
term.functor == "retract/1" -> Retract(args[0])
|
||||
term.functor == "retractall/1" -> RetractAll(args[0])
|
||||
term.functor == "assert/1" -> {
|
||||
term.functor == FunctorInfo.of("dynamic/1") -> Dynamic(FunctorInfo.of((args[0] as Atom).name))
|
||||
term.functor == FunctorInfo.of("retract/1") -> Retract(args[0])
|
||||
term.functor == FunctorInfo.of("retractall/1") -> RetractAll(args[0])
|
||||
term.functor == FunctorInfo.of("assert/1") -> {
|
||||
if (args[0] is Rule) {
|
||||
Assert(args[0] as Rule)
|
||||
} else {
|
||||
Assert(Fact(args[0] as Head))
|
||||
}
|
||||
}
|
||||
term.functor == "asserta/1" -> {
|
||||
term.functor == FunctorInfo.of("asserta/1") -> {
|
||||
if (args[0] is Rule) {
|
||||
AssertA(args[0] as Rule)
|
||||
} else {
|
||||
AssertA(Fact(args[0] as Head))
|
||||
}
|
||||
}
|
||||
term.functor == "assertz/1" -> {
|
||||
term.functor == FunctorInfo.of("assertz/1") -> {
|
||||
if (args[0] is Rule) {
|
||||
AssertZ(args[0] as Rule)
|
||||
} else {
|
||||
|
@ -120,10 +120,10 @@ open class Preprocessor {
|
|||
}
|
||||
|
||||
// Other
|
||||
term.functor == "write/1" -> Write(args[0])
|
||||
term.functor == "read/1" -> Read(args[0])
|
||||
term.functor == "initialization/1" -> Initialization(args[0] as Goal)
|
||||
term.functor == "forall/2" -> ForAll(args[0] as LogicOperand, args[1] as Goal)
|
||||
term.functor == FunctorInfo.of("write/1") -> Write(args[0])
|
||||
term.functor == FunctorInfo.of("read/1") -> Read(args[0])
|
||||
term.functor == FunctorInfo.of("initialization/1") -> Initialization(args[0] as Goal)
|
||||
term.functor == FunctorInfo.of("forall/2") -> ForAll(args[0] as LogicOperand, args[1] as Goal)
|
||||
|
||||
else -> {
|
||||
term.arguments = args
|
||||
|
|
Reference in a new issue