michaellperry/jinaga

Existential query conditions

michaellperry opened this issue · 0 comments

Add steps to a query to recursively test for the existence or absence of facts satisfying another query.

Create a "where" method in the Jinaga class that operates on a query specification. For example:

function uncompletedTasksInList(l) {
  return j.where({
    type: "Task",
    list: l
  }, [taskIsNotCompleted]);
}

This will append an existential condition to the query. The condition will only be satisfied if the subquery returns at least one result.

Create a "not" method in the Jinaga class that operates on a query specification. For example:

function taskIsNotCompleted(t) {
  return j.not({
    type: "TaskCompleted",
    task: t,
    completed: true
  });
}

This template function can only be used as a condition. When used, it negates the existential condition so that it only is satisfied when the subquery returns no results.

The "not" method can take an array of functions. In this usage, it is being applied at the point of usage:

function uncompletedTasksInList(l) {
  return j.where({
    type: "Task",
    list: l
  }, j.not([taskIsCompleted]));
}