The query argument is an expression in the Loom query language (see Remarks below). This language has the expressive power of the first-order predicate calculus.
The context argument is the name of the context in which query is to be evaluated.
The generators argument is a list containing one or more of the terms in query. The Loom query optimizer will prefer these terms when selecting generators for the query variables. Normally, generators are terms that are expected to generate few instances.
query-expr ::= ( {:AND | :OR} query-expr+ ) | ( {:NOT | :FAIL} query-expr ) | ( :IMPLIES query-expr query-expr ) | ( {:FOR-SOME | :FOR-ALL} ( ?Var+ ) query-expr ) | ( :COLLECT ( ?Var ) query-expr ) | ( concept instance ) | ( relation instance+ value ) | ( :SAME-AS instance instance ) | ( :SUBSET instance instance ) | ( :PREDCALL LispPredicate value+ ) | ( :ABOUT instance about-clause* )
about-clause ::= concept | ( concept ) | ( relation value ) | ( :FILLED-BY relation value+ ) | ( {:AT-LEAST | :AT-MOST | :EXACTLY} Integer relation ) | ( {:ALL | :SOME | :THE} relation concept )The query expressions appearing in the query argument above have the following syntax: Each about-term in a query :about clause has the form:
The query-expression operators have the following semantics:
Any ?-variable not bound in variables, or in the variables of a :for-some, :for-all, or :collect clause, is assumed to be bound externally. The value of an external ?-variable should be a Loom object, i.e., a concept, relation, or instance, rather than the name of such an object.
The :filled-by-list operator cannot be used in the :about clause of a query. The Loom Grammar at the end of this manual is too general in this respect.
Concepts and relations referenced by name in a query must be defined at the time the query is compiled. Instances referenced by identifier must exist at the time the query is executed.
(retrieve ?x (Artist ?x)) ==> (|I|JOE \ldots) (retrieve ?x (age Joe ?x)) ==> (39) (retrieve (?x) (age Joe ?x) :context cl-user-theory) ==> ((39)) (retrieve ?x (max (age (child Joe)) ?x)) (retrieve ?x (distance Paris Rome ?x)) (retrieve (?x ?y) (wife ?x ?y)) ==> ((|I|JOE |I|SUE) (|I|FRED |I|MARY)) (retrieve ?x (:and (Woman ?x) (Senator ?x)) :generators ((Senator ?x))) (retrieve ?x (:and (pet Joe ?x) (:not (Dog ?x)))) (retrieve ?x (:and (Artist ?x) (:fail (:or (French ?x) (resides ?x France))))) (retrieve ?x (:and (Writer ?x) (:for-some ?y (:and (author ?y ?x) (Best-Seller ?y))))) (retrieve ?x (:and (Writer ?x) (:for-all ?y (:implies (author ?y ?x) (Best-Seller ?y))))) (retrieve ?x (:and (Salesman ?x) (:same-as (home ?x) (office ?x)))) (retrieve ?x (:and (Salesman ?x) (:subset (customer ?x) (customer Joe)))) (retrieve ?x (:and (age (child Joe) ?x) (:predcall \#'oddp ?x))) (retrieve ?x (:about ?x Man (:at-least 2 child) (:exactly 0 son))) (retrieve ?x (:about ?x Man (:all child Female) (:some child Teen-Ager))) (retrieve ?x (:about ?x Man (:filled-by daughter Mary Sue))) (setq ?C (fc Artist) ?R (fr friend) ?V (fi Joe)) (retrieve ?x (:and (?C ?x) (?R ?x ?V) (:about ?x (:all ?R ?C))))