Skip to content

Commit 72820fd

Browse files
committed
feat: add directives
1 parent 2f534b7 commit 72820fd

File tree

1 file changed

+19
-7
lines changed
  • src/main/scala/io/github/kelvindev15/prolog/core

1 file changed

+19
-7
lines changed

src/main/scala/io/github/kelvindev15/prolog/core/Struct.scala

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,34 @@ object Struct:
3131
private case class StructImpl(functor: Atom, arguments: Term*) extends Struct:
3232
override val arity: Int = arguments.size
3333

34-
trait Rule extends Struct:
35-
val head: Struct
34+
trait Clause extends Struct:
35+
val head: Option[Struct]
36+
val body: Term
37+
38+
trait Directive extends Clause:
39+
override val head: Option[Struct] = None
40+
41+
trait Rule extends Clause:
42+
val head: Option[Struct]
3643
val body: Term
3744
final override val functor: Atom = CLAUSE
3845
final override val arity: Int = 2
39-
final override val arguments: Seq[Term] = Seq(head, body)
40-
final override def isGround: Boolean = head.isGround && body.isGround
41-
final override def variables: Seq[Variable] = head.variables ++ body.variables
4246

4347
object Rule:
4448
def apply(head: Struct, args: Term*): Rule = RuleImpl(head, Conjunction.wrapIfNecessary(args*))
45-
private case class RuleImpl(head: Struct, body: Term) extends Rule
49+
private case class RuleImpl(_head: Struct, body: Term) extends Rule:
50+
override val head: Option[Struct] = Option(_head)
51+
override val arguments: Seq[Term] = Seq(head.get, body)
52+
override def isGround: Boolean = head.get.isGround && body.isGround
53+
override def variables: Seq[Variable] = head.get.variables ++ body.variables
4654

4755
trait Fact extends Rule:
4856
override val body: Term = Atom("true")
4957

5058
object Fact:
5159
def apply(head: Struct): Fact = FactImpl(head)
52-
private case class FactImpl(head: Struct) extends Fact
60+
private case class FactImpl(_head: Struct) extends Fact:
61+
override val head: Option[Struct] = Option(_head)
62+
override val arguments: Seq[Term] = Seq(head.get)
63+
override def isGround: Boolean = head.get.isGround
64+
override def variables: Seq[Variable] = head.get.variables

0 commit comments

Comments
 (0)