next up previous contents
Next: Sequencing Methods Up: Calling Lisp and the Previous: The List of Values

Requesting Information from the User

The Lisp interface special forms make it easy to define functions for interacting with the user to request information for the Algernon knowledge base.

This section presents a simple user interface, intended to illustrate the basic method and encourage you to implement your own more sophisticated interface, tailored to the needs of your application.

This interface defines sets of slots associated with rules that invoke a Lisp function appropriate to that type of slot, to interact with the user.

We demonstrate these features with some more interaction regarding Adam's family. We assert that the slots friendly and age belong to sets that will allow them to inherit the interaction rules above.

  (tell '((isa (:slot friendly) Boolean-Ask-Slots)
          (isa (:slot age)      Numerical-Ask-Slots)))

For each of Adam's children, we query whether he or she is friendly. If this is known, we report the result. This is similar to a previous interaction, but specified on a rule inherited from a set.

  (ask '((child Adam ?kid)
         (friendly ?kid ?tv)
         (:eval (format t "~%Is Adam's child ~a friendly?  ~a." '?kid '?tv)))
       :comment "Ask the user to provide a truth value.")

QUERYING:  Ask the user to provide a truth value.
Is it known that (friendly ellen true)? (Y or N): y
Is it known that (friendly donna true)? (Y or N): n
Is it known that (friendly charles true)? (Y or N): y

Is Adam's child ELLEN friendly?  TRUE.
Is Adam's child CHARLES friendly?  TRUE.

 Result (1 of 2):
   Bindings:            ?tv    --- true "[true]"
                        ?kid   --- ellen "[ellen]"
                       
 Result (2 of 2):
   Bindings:            ?tv    --- true "[true]"
                        ?kid   --- charles "[charles]"
                       
  => T

Next, for each child, ask the user for the child's age. Any non-numerical value counts as refusal to answer, so the rule and the attempt to query (age ?kid ?n) fail.

  (ask '((child Adam ?kid)
         (age ?kid ?n)
         (:eval (format t "~%~a's age is ~a." '?kid '?n)))
       :comment "Ask the user to provide a numerical value.")

QUERYING:  Ask the user to provide a numerical value.

Please give me a numerical value for ?n in (age ellen ?n):  12

Please give me a numerical value for ?n in (age donna ?n):  no

Please give me a numerical value for ?n in (age charles ?n):  16

ELLEN's age is 12.
CHARLES's age is 16.

 Result (1 of 2):
   Bindings:            ?n     --- 12
                        ?kid   --- ellen "[ellen]"
                       
 Result (2 of 2):
   Bindings:            ?n     --- 16
                        ?kid   --- charles "[charles]"
                       
  => T

Finally, we ask the user to select one of a list of options.

  
  (ask '((:eval (format t "~%Which kid is your favorite?"))
         (:bind ?options (:values Adam child))
         (:branch ?choice (select-option '?options ))
         (:eval (format t "~%You picked ~a." '?choice)))
       :comment "Ask the user to pick one of a given set of options.")

QUERYING:  Ask the user to pick one of a given set of options.

Which kid is your favorite?

+------------------------------
| Select one (`0' for none)
+------------------------------
|   1:   ELLEN
|   2:   DONNA
|   3:   CHARLES
+------------------------------
| Select item number (1 to 3):  1

You picked ELLEN.

 Result:
   Bindings:            ?choice   --- ellen "[ellen]"
                        ?options   --- (ellen "[ellen]" donna "[donna]" charles "[charles]")
                       
  => T


next up previous contents
Next: Sequencing Methods Up: Calling Lisp and the Previous: The List of Values

Micheal S. Hewett
Tue Oct 29 10:54:13 CST 1996