Skip to content

Instantly share code, notes, and snippets.

@SanderMertens
Last active February 2, 2021 09:09
Show Gist options
  • Select an option

  • Save SanderMertens/404f33b6c40e05046c6836a02ef940c1 to your computer and use it in GitHub Desktop.

Select an option

Save SanderMertens/404f33b6c40e05046c6836a02ef940c1 to your computer and use it in GitHub Desktop.

Plecs draft

Prolog with Flecs extensions. Follows same conventions as https://gist.github.com/SanderMertens/2b0aa555601e218ea27af1096a4cc838

Atom

Simple (named) entity definition. The dot is optional (to make prolog compatible).

Bob
Alice.

Atoms (entities) are created on first occurrence.

Predicate(Subject)

Arity 1 predicate. Declare that Subject has Predicate.

Man(Bob)
Woman(Alice).

Predicates are entities themselves, and are also created on first occurrence.

Predicate(Subject, Object)

Arity 2 predicate. Declare that Subject has Predicate, Object pair.

Likes(Bob, Alice)
Likes(Alice, Bob).

Predicate(Subject){Value}

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}
    ]
  }
]

Subject predicate list

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}
]

Predicate subject list

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

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)

Removing

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment