ask [Macro]


Purpose

The ask macro is used to determine whether a proposition is true with respect to the current state of a knowledge base.

Syntax

ask query &key context 3-valued-p

Arguments

The query argument is an arbitrary 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 compiled or evaluated.

If the 3-valued-p argument is t, the query returns :true, :false, or :unknown.

Value

Normally, the ask macro returns t if the proposition is provably true, and nil otherwise. If the 3-valued-p option is selected, ask returns :true if the proposition is provably true, :false if it is provably false, and :unknown otherwise. Whether a given proposition is provably true (or false) may depend on whether open-world or closed-world semantics are currently assumed.

Remarks

  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 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:

A concept, relation, or instance may be either a symbol that names a Loom object, or a variable beginning with the character ?. An instance may also be a constant or a formula, where a formula is a list of the form (relation instance).

Any ?-variable not bound in a :for-some or :for-all 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.

Examples

(ask (Artist Joe)) ==> T 
(ask (age Joe 40) :context cl-user-theory) ==> NIL
(ask (child Joe Fred) :3-valued-p t) ==> :UNKNOWN
(ask (max (age (child Joe)) 13))
(ask (distance Paris Rome 1000))
(ask (:and (Woman Boxer) (Senator Boxer)))
(ask (:not (Dog Duke)))
(ask (:fail (:or (French Jean) (resides Jean France))))
(ask (:for-some ?y (:and (author Joe ?y) (Best-Seller ?y))))
(ask (:for-some ?y (:and (age (child Joe) ?y) (:predcall \#'oddp ?y))))
(ask (:for-all ?y (:implies (author Joe ?y) (Best-Seller ?y))))
(ask (:same-as (home Joe) (office Joe)))
(ask (:subset (customer Fred) (customer Joe)))
(ask (:about Joe (:at-least 2 child) (:exactly 0 son)))
(ask (:about Joe (:all child Female) (:some child Teen-Ager)))
(ask (:about Joe (:filled-by daughter Mary Sue)))
(setq ?C (fc Artist) ?R (fr friend) ?V (fi Fred) ?I (fi Joe))
(ask (:and (?C ?I) (?R ?I ?V) (:about ?I (:all ?R ?C))))

See Also

Last modified: Jun 1 1995