Prolog with Flecs extensions. Follows same conventions as https://gist.github.com/SanderMertens/2b0aa555601e218ea27af1096a4cc838
Simple (named) entity definition. The dot is optional (to make prolog compatible).
Bob
Alice.
Atoms (entities) are created on first occurrence.
Arity 1 predicate. Declare that Subject has Predicate.
Man(Bob)
Woman(Alice).
Predicates are entities themselves, and are also created on first occurrence.
Arity 2 predicate. Declare that Subject has Predicate, Object pair.
Likes(Bob, Alice)
Likes(Alice, Bob).
Declare that Subject has Predicate, assign value to Predicate(Subject). This requires that the Predicate is associated with a datatype. Applies to arity 1 and arity 2 predicates.
Position(Bob){x: 10, y: 20}
Position(Alice){x: 10, y: 20}.
Values may contain nested composite types and collections. Member names are optional.
Position [
Struct {
members: [
{"x", float},
{"y", float}
]
}
]
Assign multiple predicates to Subject in single statement. Inside the predicate list the Object is omitted.
Bob [ Man, (Likes, Alice) ]
Alice [ Woman, (Likes, Bob) ].
A predicate list may contain values, and may span multiple lines:
Bob [
Man,
Position{x: 10, y: 20}
]
Assign a predicate to all subjects inside the list.
(Man) {
Bob
John.
}
A predicate subject list may contain an object:
(Parent, Bob) {
John
Evelyn.
}
A predicate subject list may contain statements:
(Parent, Bob) {
Man(John)
Woman(Evelyn).
}
Predicate subject lists may be nested:
(Parent, Bob) {
(Man) {
John
David
}
(Woman) {
Evelyn
Mary.
}
}
Rules are predicates that can nest other predicates:
Meal(X) :- Food(X)
Rules may have multiple parameters:
Friend(X, Y) :- Likes(X, Y), Likes(Y, X)
Rules may contain operators:
Mortal(X) :- Man(X) || Woman(X), !God(X), ?Demigod(X)
In interactive environments subjects may be removed by prefixing them with a minus sign (-).
-Bob
Similarly, predicates may be removed from objects by prefixing them with a -.
-Man(Bob)